← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 17065: Data entry, validation, checking for min and max integer values

 

------------------------------------------------------------
revno: 17065
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Sun 2014-10-12 12:03:15 +0200
message:
  Data entry, validation, checking for min and max integer values
modified:
  dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/dhis2.validation.js


--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk

Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/dhis2.validation.js'
--- dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/dhis2.validation.js	2014-07-21 09:45:25 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/dhis2.validation.js	2014-10-12 10:03:15 +0000
@@ -30,6 +30,8 @@
 
 dhis2.util.namespace('dhis2.validation');
 
+dhis2.validation.INT_MAX_VALUE = parseInt('2147483647');
+
 /**
  * Checks if the given value is valid zero.
  */
@@ -43,22 +45,19 @@
  */
 dhis2.validation.isInt = function(value) {
   var regex = /^(0|-?[1-9]\d*)$/;
-  return regex.test(value);
+  var patternTest = regex.test(value);
+  var rangeTest = value && 
+  	parseInt(value) < dhis2.validation.INT_MAX_VALUE &&
+  	parseInt(value) > ( dhis2.validation.INT_MAX_VALUE * -1 );
+  return patternTest && rangeTest;
 };
 
 /**
- * Allow only integers inclusive between 0 and 100. 
- */
-dhis2.validation.isPercentage = function(value) {
-  return dhis2.validation.isInt(value) && parseInt(value) >= 0 && parseInt(value) <= 100;
-}
-
-/**
  * Allow only positive integers, not zero, no thousands separators.
  */
 dhis2.validation.isPositiveInt = function(value) {
   var regex = /^[1-9]\d*$/;
-  return regex.test(value);
+  return regex.test(value) && dhis2.validation.isInt(value);
 };
 
 /**
@@ -66,7 +65,7 @@
  */
 dhis2.validation.isZeroOrPositiveInt = function(value) {
   var regex = /(^0$)|(^[1-9]\d*$)/;
-  return regex.test(value);
+  return regex.test(value) && dhis2.validation.isInt(value);
 };
 
 /**
@@ -74,7 +73,7 @@
  */
 dhis2.validation.isNegativeInt = function(value) {
   var regex = /^-[1-9]\d*$/;
-  return regex.test(value);
+  return regex.test(value) && dhis2.validation.isInt(value);
 };
 
 /**
@@ -101,6 +100,13 @@
 };
 
 /**
+ * Allow only integers inclusive between 0 and 100. 
+ */
+dhis2.validation.isPercentage = function(value) {
+  return dhis2.validation.isInt(value) && parseInt(value) >= 0 && parseInt(value) <= 100;
+}
+
+/**
  * Returns true if the provided string argument is to be considered a unit
  * interval, which implies that the value is numeric and inclusive between 0
  * and 1.