commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mr...@apache.org
Subject svn commit: r239517 - /jakarta/commons/proper/validator/trunk/src/javascript/org/apache/commons/validator/javascript/validateDate.js
Date Wed, 24 Aug 2005 03:48:04 GMT
Author: mrdon
Date: Tue Aug 23 20:48:03 2005
New Revision: 239517

URL: http://svn.apache.org/viewcvs?rev=239517&view=rev
Log:
Added support for datePattern on date validator
PR: 22384

Modified:
    jakarta/commons/proper/validator/trunk/src/javascript/org/apache/commons/validator/javascript/validateDate.js

Modified: jakarta/commons/proper/validator/trunk/src/javascript/org/apache/commons/validator/javascript/validateDate.js
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/validator/trunk/src/javascript/org/apache/commons/validator/javascript/validateDate.js?rev=239517&r1=239516&r2=239517&view=diff
==============================================================================
--- jakarta/commons/proper/validator/trunk/src/javascript/org/apache/commons/validator/javascript/validateDate.js
(original)
+++ jakarta/commons/proper/validator/trunk/src/javascript/org/apache/commons/validator/javascript/validateDate.js
Tue Aug 23 20:48:03 2005
@@ -17,10 +17,13 @@
        for (x in oDate) {
            var field = form[oDate[x][0]];
            var value = field.value;
+           var isStrict = true;
            var datePattern = oDate[x][2]("datePatternStrict");
            // try loose pattern
-           if (datePattern == null)
+           if (datePattern == null) {
                datePattern = oDate[x][2]("datePattern");
+               isStrict = false;
+           }    
            if ((field.type == 'hidden' ||
                 field.type == 'text' ||
                 field.type == 'textarea') &&
@@ -38,13 +41,21 @@
                      var delim1 = datePattern.substring(iDelim1, iDelim1 + 1);
                      var delim2 = datePattern.substring(iDelim2, iDelim2 + 1);
                      if (iDelim1 == orderDay && iDelim2 == orderYear) {
-                        dateRegexp = new RegExp("^(\\d{2})(\\d{2})(\\d{4})$");
+                        dateRegexp = isStrict 
+                             ? new RegExp("^(\\d{2})(\\d{2})(\\d{4})$") 
+                             : new RegExp("^(\\d{1,2})(\\d{1,2})(\\d{4})$");
                      } else if (iDelim1 == orderDay) {
-                        dateRegexp = new RegExp("^(\\d{2})(\\d{2})[" + delim2 + "](\\d{4})$");
+                        dateRegexp = isStrict 
+                             ? new RegExp("^(\\d{2})(\\d{2})[" + delim2 + "](\\d{4})$")
+                             : new RegExp("^(\\d{1,2})(\\d{1,2})[" + delim2 + "](\\d{4})$");
                      } else if (iDelim2 == orderYear) {
-                        dateRegexp = new RegExp("^(\\d{2})[" + delim1 + "](\\d{2})(\\d{4})$");
+                        dateRegexp = isStrict
+                             ? new RegExp("^(\\d{2})[" + delim1 + "](\\d{2})(\\d{4})$")
+                             : new RegExp("^(\\d{1,2})[" + delim1 + "](\\d{1,2})(\\d{4})$");
                      } else {
-                        dateRegexp = new RegExp("^(\\d{2})[" + delim1 + "](\\d{2})[" + delim2
+ "](\\d{4})$");
+                        dateRegexp = isStrict
+                             ? new RegExp("^(\\d{2})[" + delim1 + "](\\d{2})[" + delim2 +
"](\\d{4})$")
+                             : new RegExp("^(\\d{1,2})[" + delim1 + "](\\d{1,2})[" + delim2
+ "](\\d{4})$");
                      }
                      var matched = dateRegexp.exec(value);
                      if(matched != null) {
@@ -68,19 +79,27 @@
                      var delim1 = datePattern.substring(iDelim1, iDelim1 + 1);
                      var delim2 = datePattern.substring(iDelim2, iDelim2 + 1);
                      if (iDelim1 == orderMonth && iDelim2 == orderYear) {
-                         dateRegexp = new RegExp("^(\\d{2})(\\d{2})(\\d{4})$");
+                         dateRegexp = isStrict 
+                            ? new RegExp("^(\\d{2})(\\d{2})(\\d{4})$")
+                            : new RegExp("^(\\d{1,2})(\\d{1,2})(\\d{4})$");
                      } else if (iDelim1 == orderMonth) {
-                         dateRegexp = new RegExp("^(\\d{2})(\\d{2})[" + delim2 + "](\\d{4})$");
+                         dateRegexp = isStrict
+                            ? new RegExp("^(\\d{2})(\\d{2})[" + delim2 + "](\\d{4})$")
+                            : new RegExp("^(\\d{1,2})(\\d{1,2})[" + delim2 + "](\\d{4})$");
                      } else if (iDelim2 == orderYear) {
-                         dateRegexp = new RegExp("^(\\d{2})[" + delim1 + "](\\d{2})(\\d{4})$");
+                         dateRegexp = isStrict
+                            ? new RegExp("^(\\d{2})[" + delim1 + "](\\d{2})(\\d{4})$")
+                            : new RegExp("^(\\d{1,2})[" + delim1 + "](\\d{1,2})(\\d{4})$");
                      } else {
-                         dateRegexp = new RegExp("^(\\d{2})[" + delim1 + "](\\d{2})[" + delim2
+ "](\\d{4})$");
+                         dateRegexp = isStrict
+                            ? new RegExp("^(\\d{2})[" + delim1 + "](\\d{2})[" + delim2 +
"](\\d{4})$")
+                            : new RegExp("^(\\d{1,2})[" + delim1 + "](\\d{1,2})[" + delim2
+ "](\\d{4})$");
                      }
                      var matched = dateRegexp.exec(value);
                      if(matched != null) {
                          if (!isValidDate(matched[1], matched[2], matched[3])) {
                              if (i == 0) {
-                         focusField = field;
+                                  focusField = field;
                              }
                              fields[i++] = oDate[x][1];
                              bValid =  false;
@@ -98,13 +117,21 @@
                      var delim1 = datePattern.substring(iDelim1, iDelim1 + 1);
                      var delim2 = datePattern.substring(iDelim2, iDelim2 + 1);
                      if (iDelim1 == orderMonth && iDelim2 == orderDay) {
-                         dateRegexp = new RegExp("^(\\d{4})(\\d{2})(\\d{2})$");
+                         dateRegexp = isStrict
+                            ? new RegExp("^(\\d{4})(\\d{2})(\\d{2})$")
+                            : new RegExp("^(\\d{4})(\\d{1,2})(\\d{1,2})$");
                      } else if (iDelim1 == orderMonth) {
-                         dateRegexp = new RegExp("^(\\d{4})(\\d{2})[" + delim2 + "](\\d{2})$");
+                         dateRegexp = isStrict
+                            ? new RegExp("^(\\d{4})(\\d{2})[" + delim2 + "](\\d{2})$")
+                            : new RegExp("^(\\d{4})(\\d{1,2})[" + delim2 + "](\\d{1,2})$");
                      } else if (iDelim2 == orderDay) {
-                         dateRegexp = new RegExp("^(\\d{4})[" + delim1 + "](\\d{2})(\\d{2})$");
+                         dateRegexp = isStrict
+                            ? new RegExp("^(\\d{4})[" + delim1 + "](\\d{2})(\\d{2})$")
+                            : new RegExp("^(\\d{4})[" + delim1 + "](\\d{1,2})(\\d{1,2})$");
                      } else {
-                         dateRegexp = new RegExp("^(\\d{4})[" + delim1 + "](\\d{2})[" + delim2
+ "](\\d{2})$");
+                         dateRegexp = isStrict
+                            ? new RegExp("^(\\d{4})[" + delim1 + "](\\d{2})[" + delim2 +
"](\\d{2})$")
+                            : new RegExp("^(\\d{4})[" + delim1 + "](\\d{1,2})[" + delim2
+ "](\\d{1,2})$");
                      }
                      var matched = dateRegexp.exec(value);
                      if(matched != null) {



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message