[interchange] Add numeric ordercheck
Jon Jensen <[email protected]>
| Newsgroups | gmane.comp.web.interchange.cvs |
|---|---|
| Message-ID | <[email protected]> |
commit 528ff5442ed28dc74a665f81e43d132a072c15b7 Author: Jon Jensen <[email protected]> Date: Thu Mar 25 09:36:54 2010 -0600 Add numeric ordercheck Allowed: 1 0.5 -1 -1.0 -1.0000 -0.5 Disallowed: 1. .1 1.1.1 +1 1,0 Thanks to Ton Verhagen for making it happen. MANIFEST | 1 + code/OrderCheck/numeric.oc | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 0 deletions(-) --- diff --git a/MANIFEST b/MANIFEST index 08312e8..9ec3966 100644 --- a/MANIFEST +++ b/MANIFEST @@ -101,6 +101,7 @@ code/OrderCheck/isbn.oc code/OrderCheck/length.oc code/OrderCheck/match.oc code/OrderCheck/natural.oc +code/OrderCheck/numeric.oc code/OrderCheck/regex.oc code/OrderCheck/relative_filename.oc code/OrderCheck/unique.oc diff --git a/code/OrderCheck/numeric.oc b/code/OrderCheck/numeric.oc new file mode 100644 index 0000000..4267c4b --- /dev/null +++ b/code/OrderCheck/numeric.oc @@ -0,0 +1,21 @@ +# Copyright 2010 Interchange Development Group and others +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. See the LICENSE file for details. + +CodeDef numeric OrderCheck +CodeDef numeric Description Numeric +CodeDef numeric Routine <<EOR +sub { + my ($ref, $name, $value, $msg) = @_; + + if (defined($value) and $value =~ /\A-?\d+(\.\d+)?\z/) { + return (1, $name, ''); + } + else { + return (0, $name, defined($msg) ? $msg : 'not numeric'); + } +} +EOR