[interchange] Rename numeric ordercheck to numeric_strict, and add laxer numeric check

Jon Jensen <[email protected]>
Newsgroups gmane.comp.web.interchange.cvs
Message-ID <[email protected]>
commit 5e03d9ebceeecd1726fd8db77c580cfc660f569c
Author: Jon Jensen <[email protected]>
Date:   Wed Apr 7 14:38:39 2010 -0600

    Rename numeric ordercheck to numeric_strict, and add laxer numeric check

 code/OrderCheck/numeric.oc        |    4 +++-
 code/OrderCheck/numeric_strict.oc |   21 +++++++++++++++++++++
 2 files changed, 24 insertions(+), 1 deletions(-)
---
diff --git a/code/OrderCheck/numeric.oc b/code/OrderCheck/numeric.oc
index 4267c4b..c44b1c4 100644
--- a/code/OrderCheck/numeric.oc
+++ b/code/OrderCheck/numeric.oc
@@ -8,10 +8,12 @@
 CodeDef numeric OrderCheck
 CodeDef numeric Description Numeric
 CodeDef numeric Routine <<EOR
+
 sub {
     my ($ref, $name, $value, $msg) = @_;
+    use Scalar::Util qw/looks_like_number/;
 
-    if (defined($value) and $value =~ /\A-?\d+(\.\d+)?\z/) {
+    if (looks_like_number($value)) {
         return (1, $name, '');
     }
     else {
diff --git a/code/OrderCheck/numeric_strict.oc b/code/OrderCheck/numeric_strict.oc
new file mode 100644
index 0000000..0a6b1d1
--- /dev/null
+++ b/code/OrderCheck/numeric_strict.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_strict OrderCheck
+CodeDef numeric_strict Description Numeric (strict)
+CodeDef numeric_strict 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 strict numeric');
+    }
+}
+EOR
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.