Added: struts/shale/trunk/use-cases/src/web/WEB-INF/validator-rules.xml
URL: 
http://svn.apache.org/viewcvs/struts/shale/trunk/use-cases/src/web/WEB-INF/validator-rules.xml?view=auto&rev=161825
==============================================================================
--- struts/shale/trunk/use-cases/src/web/WEB-INF/validator-rules.xml (added)
+++ struts/shale/trunk/use-cases/src/web/WEB-INF/validator-rules.xml Mon Apr 18 
19:07:17 2005
@@ -0,0 +1,896 @@
+<!DOCTYPE form-validation PUBLIC
+          "-//Apache Software Foundation//DTD Commons Validator Rules 
Configuration 1.0//EN"
+          "http://jakarta.apache.org/commons/dtds/validator_1_0.dtd";>
+<form-validation>
+
+   <global>
+
+      <validator name="required"
+            classname="org.apache.shale.validator.CommonsValidator"
+               method="isSupplied"
+         methodParams="java.lang.String"
+                  msg="errors.required">
+
+         <javascript><![CDATA[
+            function validateRequired(form) {
+                var isValid = true;
+                var focusField = null;
+                var i = 0;
+                var fields = new Array();
+                oRequired = new required();
+                for (x in oRequired) {
+                   var field = form[oRequired[x][0]];
+                   
+                    if (field.type == 'text' ||
+                        field.type == 'textarea' ||
+                        field.type == 'file' ||
+                        field.type == 'select-one' ||
+                        field.type == 'radio' ||
+                        field.type == 'password') {
+                        
+                        var value = '';
+                  // get field's value
+                  if (field.type == "select-one") {
+                     var si = field.selectedIndex;
+                     if (si >= 0) {
+                        value = field.options[si].value;
+                     }
+                  } else {
+                     value = field.value;
+                  }
+                        
+                        if (trim(value).length == 0) {
+                        
+                           if (i == 0) {
+                               focusField = field;
+                           }
+                           fields[i++] = oRequired[x][1];
+                           isValid = false;
+                        }
+                    }
+                }
+                if (fields.length > 0) {
+                   focusField.focus();
+                   alert(fields.join('\n'));
+                }
+                return isValid;
+            }
+            
+            // Trim whitespace from left and right sides of s.
+            function trim(s) {
+                return s.replace( /^\s*/, "" ).replace( /\s*$/, "" );
+            }
+            
+            ]]>
+         </javascript>
+
+      </validator>
+
+      <validator name="minlength"
+            classname="org.apache.commons.validator.GenericValidator"
+               method="minLength"
+         methodParams="java.lang.String,int"
+              depends=""
+                  msg="errors.minlength">
+
+         <javascript><![CDATA[
+            function validateMinLength(form) {
+                var isValid = true;
+                var focusField = null;
+                var i = 0;
+                var fields = new Array();
+                oMinLength = new minlength();
+                for (x in oMinLength) {
+                    var field = form[oMinLength[x][0]];
+                    
+                    if (field.type == 'text' ||
+                        field.type == 'textarea') {
+                        
+                        var iMin = parseInt(oMinLength[x][2]("minlength"));
+                        if ((trim(field.value).length > 0) && 
(field.value.length < iMin)) {
+                            if (i == 0) {
+                                focusField = field;
+                            }
+                            fields[i++] = oMinLength[x][1];
+                            isValid = false;
+                        }
+                    }
+                }
+                if (fields.length > 0) {
+                   focusField.focus();
+                   alert(fields.join('\n'));
+                }
+                return isValid;
+            }]]>
+         </javascript>
+
+      </validator>
+
+
+      <validator name="maxlength"
+            classname="org.apache.commons.validator.GenericValidator"
+               method="maxLength"
+         methodParams="java.lang.String,int"
+              depends=""
+                  msg="errors.maxlength">
+
+         <javascript><![CDATA[
+            function validateMaxLength(form) {
+                var isValid = true;
+                var focusField = null;
+                var i = 0;
+                var fields = new Array();
+                oMaxLength = new maxlength();
+                for (x in oMaxLength) {
+                    var field = form[oMaxLength[x][0]];
+                    
+                    if (field.type == 'text' ||
+                        field.type == 'textarea') {
+                        
+                        var iMax = parseInt(oMaxLength[x][2]("maxlength"));
+                        if (field.value.length > iMax) {
+                            if (i == 0) {
+                                focusField = field;
+                            }
+                            fields[i++] = oMaxLength[x][1];
+                            isValid = false;
+                        }
+                    }
+                }
+                if (fields.length > 0) {
+                   focusField.focus();
+                   alert(fields.join('\n'));
+                }
+                return isValid;
+            }]]>
+         </javascript>
+
+      </validator>
+
+
+      <validator name="mask"
+            classname="org.apache.commons.validator.GenericValidator"
+               method="matchRegexp"
+         methodParams="java.lang.String,java.lang.String"
+              depends=""
+                  msg="errors.invalid">
+
+         <javascript><![CDATA[
+            function validateMask(form) {
+                var isValid = true;
+                var focusField = null;
+                var i = 0;
+                var fields = new Array();
+                oMasked = new mask();
+                for (x in oMasked) {
+                    var field = form[oMasked[x][0]];
+                    
+                    if ((field.type == 'text' || 
+                         field.type == 'textarea') && 
+                         (field.value.length > 0)) {
+                        
+                        if (!matchPattern(field.value, oMasked[x][2]("mask"))) 
{
+                            if (i == 0) {
+                                focusField = field;
+                            }
+                            fields[i++] = oMasked[x][1];
+                            isValid = false;
+                        }
+                    }
+                }
+                
+                if (fields.length > 0) {
+                   focusField.focus();
+                   alert(fields.join('\n'));
+                }
+                return isValid;
+            }
+
+            function matchPattern(value, mask) {
+               return mask.exec(value);
+            }]]>
+         </javascript>
+
+      </validator>
+
+
+      <validator name="byte"
+            classname="org.apache.commons.validator.GenericValidator"
+               method="isByte"
+         methodParams="java.lang.String"
+              depends=""
+                  msg="errors.byte"
+       jsFunctionName="ByteValidations">
+
+         <javascript><![CDATA[
+            function validateByte(form) {
+                var bValid = true;
+                var focusField = null;
+                var i = 0;
+                var fields = new Array();
+                oByte = new ByteValidations();
+                for (x in oByte) {
+                   var field = form[oByte[x][0]];
+                   
+                    if (field.type == 'text' ||
+                        field.type == 'textarea' ||
+                        field.type == 'select-one' ||
+                  field.type == 'radio') {
+
+                  var value = '';
+                  // get field's value
+                  if (field.type == "select-one") {
+                     var si = field.selectedIndex;
+                     if (si >= 0) {
+                        value = field.options[si].value;
+                     }
+                  } else {
+                     value = field.value;
+                  }
+                        
+                        if (value.length > 0) {
+                            if (!isAllDigits(value)) {
+                                bValid = false;
+                                if (i == 0) {
+                                    focusField = field;
+                                }
+                                fields[i++] = oByte[x][1];
+
+                            } else {
+
+                               var iValue = parseInt(value);
+                               if (isNaN(iValue) || !(iValue >= -128 && iValue 
<= 127)) {
+                                   if (i == 0) {
+                                       focusField = field;
+                                   }
+                                   fields[i++] = oByte[x][1];
+                                   bValid = false;
+                               }
+                            }
+                  }
+                  
+                    }
+                }
+                if (fields.length > 0) {
+                   focusField.focus();
+                   alert(fields.join('\n'));
+                }
+                return bValid;
+            }]]>
+         </javascript>
+
+      </validator>
+
+
+      <validator name="short"
+            classname="org.apache.commons.validator.GenericValidator"
+               method="isShort"
+         methodParams="java.lang.String"
+              depends=""
+                  msg="errors.short"
+       jsFunctionName="ShortValidations">
+
+         <javascript><![CDATA[
+            function validateShort(form) {
+                var bValid = true;
+                var focusField = null;
+                var i = 0;
+                var fields = new Array();
+                oShort = new ShortValidations();
+                for (x in oShort) {
+                   var field = form[oShort[x][0]];
+                   
+                    if (field.type == 'text' ||
+                        field.type == 'textarea' ||
+                        field.type == 'select-one' ||
+                        field.type == 'radio') {
+                        
+                        var value = '';
+                  // get field's value
+                  if (field.type == "select-one") {
+                     var si = field.selectedIndex;
+                     if (si >= 0) {
+                        value = field.options[si].value;
+                     }
+                  } else {
+                     value = field.value;
+                  }
+                        
+                        if (value.length > 0) {
+                            if (!isAllDigits(value)) {
+                                bValid = false;
+                                if (i == 0) {
+                                    focusField = field;
+                                }
+                                fields[i++] = oShort[x][1];
+
+                            } else {
+                        
+                               var iValue = parseInt(value);
+                               if (isNaN(iValue) || !(iValue >= -32768 && 
iValue <= 32767)) {
+                                   if (i == 0) {
+                                       focusField = field;
+                                   }
+                                   fields[i++] = oShort[x][1];
+                                   bValid = false;
+                               }
+                          }
+                       }
+                    }
+                }
+                if (fields.length > 0) {
+                   focusField.focus();
+                   alert(fields.join('\n'));
+                }
+                return bValid;
+            }]]>
+         </javascript>
+
+      </validator>
+
+
+      <validator name="integer"
+            classname="org.apache.commons.validator.GenericValidator"
+               method="isInt"
+         methodParams="java.lang.String"
+              depends=""
+                  msg="errors.integer"
+       jsFunctionName="IntegerValidations">
+
+         <javascript><![CDATA[
+            function validateInteger(form) {
+                var bValid = true;
+                var focusField = null;
+                var i = 0;
+                var fields = new Array();
+                oInteger = new IntegerValidations();
+                for (x in oInteger) {
+                   var field = form[oInteger[x][0]];
+
+                    if (field.type == 'text' ||
+                        field.type == 'textarea' ||
+                        field.type == 'select-one' ||
+                        field.type == 'radio') {
+                        
+                        var value = '';
+                  // get field's value
+                  if (field.type == "select-one") {
+                     var si = field.selectedIndex;
+                      if (si >= 0) {
+                         value = field.options[si].value;
+                      }
+                  } else {
+                     value = field.value;
+                  }
+                        
+                        if (value.length > 0) {
+                        
+                            if (!isAllDigits(value)) {
+                                bValid = false;
+                                if (i == 0) {
+                                   focusField = field;
+                               }
+                          fields[i++] = oInteger[x][1];
+                          
+                            } else {
+                               var iValue = parseInt(value);
+                               if (isNaN(iValue) || !(iValue >= -2147483648 && 
iValue <= 2147483647)) {
+                                   if (i == 0) {
+                                       focusField = field;
+                                   }
+                                   fields[i++] = oInteger[x][1];
+                                   bValid = false;
+                              }
+                           }
+                       }
+                    }
+                }
+                if (fields.length > 0) {
+                   focusField.focus();
+                   alert(fields.join('\n'));
+                }
+                return bValid;
+            }
+
+            function isAllDigits(argvalue) {
+                argvalue = argvalue.toString();
+                var validChars = "0123456789";
+                var startFrom = 0;
+                if (argvalue.substring(0, 2) == "0x") {
+                   validChars = "0123456789abcdefABCDEF";
+                   startFrom = 2;
+                } else if (argvalue.charAt(0) == "0") {
+                   validChars = "01234567";
+                   startFrom = 1;
+                } else if (argvalue.charAt(0) == "-") {
+                    startFrom = 1;
+                }
+                
+                for (var n = startFrom; n < argvalue.length; n++) {
+                    if (validChars.indexOf(argvalue.substring(n, n+1)) == -1) 
return false;
+                }
+                return true;
+            }]]>
+         </javascript>
+
+      </validator>
+
+      <validator name="float"
+            classname="org.apache.commons.validator.GenericValidator"
+               method="isDouble"
+         methodParams="double"
+              depends=""
+                  msg="errors.float"
+       jsFunctionName="FloatValidations">
+
+         <javascript><![CDATA[
+            function validateFloat(form) {
+                var bValid = true;
+                var focusField = null;
+                var i = 0;
+                var fields = new Array();
+                oFloat = new FloatValidations();
+                for (x in oFloat) {
+                   var field = form[oFloat[x][0]];
+                   
+                    if (field.type == 'text' ||
+                        field.type == 'textarea' ||
+                        field.type == 'select-one' ||
+                        field.type == 'radio') {
+                        
+                       var value = '';
+                  // get field's value
+                  if (field.type == "select-one") {
+                     var si = field.selectedIndex;
+                     if (si >= 0) {
+                         value = field.options[si].value;
+                     }
+                  } else {
+                     value = field.value;
+                  }
+                        
+                        if (value.length > 0) {
+                            // remove '.' before checking digits
+                            var tempArray = value.split('.');
+                            var joinedString= tempArray.join('');
+
+                            if (!isAllDigits(joinedString)) {
+                                bValid = false;
+                                if (i == 0) {
+                                    focusField = field;
+                                }
+                                fields[i++] = oFloat[x][1];
+
+                            } else {
+                               var iValue = parseFloat(value);
+                               if (isNaN(iValue)) {
+                                   if (i == 0) {
+                                       focusField = field;
+                                   }
+                                   fields[i++] = oFloat[x][1];
+                                   bValid = false;
+                               }
+                            }
+                        }
+                    }
+                }
+                if (fields.length > 0) {
+                   focusField.focus();
+                   alert(fields.join('\n'));
+                }
+                return bValid;
+            }]]>
+         </javascript>
+
+      </validator>
+
+      <validator name="date"
+            classname="org.apache.shale.validator.CommonsValidator"
+               method="isDate"
+         methodParams="java.lang.String,java.lang.String"
+              depends=""
+                  msg="errors.date"
+       jsFunctionName="DateValidations">
+
+         <javascript><![CDATA[
+            function validateDate(form) {
+               var bValid = true;
+               var focusField = null;
+               var i = 0;
+               var fields = new Array();
+               oDate = new DateValidations();
+               for (x in oDate) {
+                   var value = form[oDate[x][0]].value;
+                   var datePattern = oDate[x][2]("datePatternStrict");
+                   if ((form[oDate[x][0]].type == 'text' ||
+                        form[oDate[x][0]].type == 'textarea') &&
+                       (value.length > 0) &&
+                       (datePattern.length > 0)) {
+                     var MONTH = "MM";
+                     var DAY = "dd";
+                     var YEAR = "yyyy";
+                     var orderMonth = datePattern.indexOf(MONTH);
+                     var orderDay = datePattern.indexOf(DAY);
+                     var orderYear = datePattern.indexOf(YEAR);
+                     if ((orderDay < orderYear && orderDay > orderMonth)) {
+                         var iDelim1 = orderMonth + MONTH.length;
+                         var iDelim2 = orderDay + DAY.length;
+                         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})$");
+                         } else if (iDelim1 == orderDay) {
+                            dateRegexp = new RegExp("^(\\d{2})(\\d{2})[" + 
delim2 + "](\\d{4})$");
+                         } else if (iDelim2 == orderYear) {
+                            dateRegexp = new RegExp("^(\\d{2})[" + delim1 + 
"](\\d{2})(\\d{4})$");
+                         } else {
+                            dateRegexp = new RegExp("^(\\d{2})[" + delim1 + 
"](\\d{2})[" + delim2 + "](\\d{4})$");
+                         }
+                         var matched = dateRegexp.exec(value);
+                         if(matched != null) {
+                            if (!isValidDate(matched[2], matched[1], 
matched[3])) {
+                               if (i == 0) {
+                                   focusField = form[oDate[x][0]];
+                               }
+                               fields[i++] = oDate[x][1];
+                               bValid =  false;
+                            }
+                         } else {
+                            if (i == 0) {
+                                focusField = form[oDate[x][0]];
+                            }
+                            fields[i++] = oDate[x][1];
+                            bValid =  false;
+                         }
+                     } else if ((orderMonth < orderYear && orderMonth > 
orderDay)) {
+                         var iDelim1 = orderDay + DAY.length;
+                         var iDelim2 = orderMonth + MONTH.length;
+                         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})$");
+                         } else if (iDelim1 == orderMonth) {
+                             dateRegexp = new RegExp("^(\\d{2})(\\d{2})[" + 
delim2 + "](\\d{4})$");
+                         } else if (iDelim2 == orderYear) {
+                             dateRegexp = new RegExp("^(\\d{2})[" + delim1 + 
"](\\d{2})(\\d{4})$");
+                         } else {
+                             dateRegexp = new RegExp("^(\\d{2})[" + delim1 + 
"](\\d{2})[" + delim2 + "](\\d{4})$");
+                         }
+                         var matched = dateRegexp.exec(value);
+                         if(matched != null) {
+                             if (!isValidDate(matched[1], matched[2], 
matched[3])) {
+                                 if (i == 0) {
+                                     focusField = form[oDate[x][0]];
+                                 }
+                                 fields[i++] = oDate[x][1];
+                                 bValid =  false;
+                              }
+                         } else {
+                             if (i == 0) {
+                                 focusField = form[oDate[x][0]];
+                             }
+                             fields[i++] = oDate[x][1];
+                             bValid =  false;
+                         }
+                     } else if ((orderMonth > orderYear && orderMonth < 
orderDay)) {
+                         var iDelim1 = orderYear + YEAR.length;
+                         var iDelim2 = orderMonth + MONTH.length;
+                         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})$");
+                         } else if (iDelim1 == orderMonth) {
+                             dateRegexp = new RegExp("^(\\d{4})(\\d{2})[" + 
delim2 + "](\\d{2})$");
+                         } else if (iDelim2 == orderDay) {
+                             dateRegexp = new RegExp("^(\\d{4})[" + delim1 + 
"](\\d{2})(\\d{2})$");
+                         } else {
+                             dateRegexp = new RegExp("^(\\d{4})[" + delim1 + 
"](\\d{2})[" + delim2 + "](\\d{2})$");
+                         }
+                         var matched = dateRegexp.exec(value);
+                         if(matched != null) {
+                             if (!isValidDate(matched[3], matched[2], 
matched[1])) {
+                                 if (i == 0) {
+                                     focusField = form[oDate[x][0]];
+                                  }
+                                  fields[i++] = oDate[x][1];
+                                  bValid =  false;
+                              }
+                          } else {
+                              if (i == 0) {
+                                  focusField = form[oDate[x][0]];
+                              }
+                              fields[i++] = oDate[x][1];
+                              bValid =  false;
+                          }
+                     } else {
+                         if (i == 0) {
+                             focusField = form[oDate[x][0]];
+                         }
+                         fields[i++] = oDate[x][1];
+                         bValid =  false;
+                     }
+                  }
+               }
+               if (fields.length > 0) {
+                  focusField.focus();
+                  alert(fields.join('\n'));
+               }
+               return bValid;
+            }
+
+       function isValidDate(day, month, year) {
+           if (month < 1 || month > 12) {
+                    return false;
+                }
+                if (day < 1 || day > 31) {
+                    return false;
+                }
+                if ((month == 4 || month == 6 || month == 9 || month == 11) &&
+                    (day == 31)) {
+                    return false;
+                }
+                if (month == 2) {
+                    var leap = (year % 4 == 0 &&
+                               (year % 100 != 0 || year % 400 == 0));
+                    if (day>29 || (day == 29 && !leap)) {
+                        return false;
+                    }
+                }
+                return true;
+            }]]>
+         </javascript>
+
+      </validator>
+
+      <validator name="intRange"
+            classname="org.apache.commons.validator.GenericValidator"
+               method="isInRange"
+         methodParams="int,int,int"
+              depends="integer"
+                  msg="errors.range">
+
+         <javascript><![CDATA[
+            function validateIntRange(form) {
+                var isValid = true;
+                var focusField = null;
+                var i = 0;
+                var fields = new Array();
+                oRange = new intRange();
+                for (x in oRange) {
+                    var field = form[oRange[x][0]];
+                    
+                    if ((field.type == 'text' ||
+                         field.type == 'textarea') &&
+                        (field.value.length > 0)) {
+                        
+                        var iMin = parseInt(oRange[x][2]("min"));
+                        var iMax = parseInt(oRange[x][2]("max"));
+                        var iValue = parseInt(field.value);
+                        if (!(iValue >= iMin && iValue <= iMax)) {
+                            if (i == 0) {
+                                focusField = field;
+                            }
+                            fields[i++] = oRange[x][1];
+                            isValid = false;
+                        }
+                    }
+                }
+                if (fields.length > 0) {
+                    focusField.focus();
+                    alert(fields.join('\n'));
+                }
+                return isValid;
+            }]]>
+         </javascript>
+
+      </validator>
+
+      <validator name="floatRange"
+            classname="org.apache.commons.validator.GenericValidator"
+               method="isInRange"
+         methodParams="double,double,double"
+              depends="float"
+                  msg="errors.range">
+
+         <javascript><![CDATA[
+            function validateFloatRange(form) {
+                var isValid = true;
+                var focusField = null;
+                var i = 0;
+                var fields = new Array();
+                oRange = new floatRange();
+                for (x in oRange) {
+                    var field = form[oRange[x][0]];
+                    
+                    if ((field.type == 'text' ||
+                         field.type == 'textarea') &&
+                        (field.value.length > 0)) {
+                        
+                        var fMin = parseFloat(oRange[x][2]("min"));
+                        var fMax = parseFloat(oRange[x][2]("max"));
+                        var fValue = parseFloat(field.value);
+                        if (!(fValue >= fMin && fValue <= fMax)) {
+                            if (i == 0) {
+                                focusField = field;
+                            }
+                            fields[i++] = oRange[x][1];
+                            isValid = false;
+                        }
+                    }
+                }
+                if (fields.length > 0) {
+                    focusField.focus();
+                    alert(fields.join('\n'));
+                }
+                return isValid;
+            }]]>
+         </javascript>
+
+      </validator>
+
+      <validator name="creditCard"
+            classname="org.apache.commons.validator.GenericValidator"
+               method="isCreditCard"
+         methodParams="java.lang.String"
+              depends=""
+                  msg="errors.creditcard">
+
+         <javascript><![CDATA[
+            function validateCreditCard(form) {
+                var bValid = true;
+                var focusField = null;
+                var i = 0;
+                var fields = new Array();
+                oCreditCard = new creditCard();
+                for (x in oCreditCard) {
+                    if ((form[oCreditCard[x][0]].type == 'text' ||
+                         form[oCreditCard[x][0]].type == 'textarea') &&
+                        (form[oCreditCard[x][0]].value.length > 0)) {
+                        if (!luhnCheck(form[oCreditCard[x][0]].value)) {
+                            if (i == 0) {
+                                focusField = form[oCreditCard[x][0]];
+                            }
+                            fields[i++] = oCreditCard[x][1];
+                            bValid = false;
+                        }
+                    }
+                }
+                if (fields.length > 0) {
+                    focusField.focus();
+                    alert(fields.join('\n'));
+                }
+                return bValid;
+            }
+
+            /**
+             * Reference: http://www.ling.nwu.edu/~sburke/pub/luhn_lib.pl
+             */
+            function luhnCheck(cardNumber) {
+                if (isLuhnNum(cardNumber)) {
+                    var no_digit = cardNumber.length;
+                    var oddoeven = no_digit & 1;
+                    var sum = 0;
+                    for (var count = 0; count < no_digit; count++) {
+                        var digit = parseInt(cardNumber.charAt(count));
+                        if (!((count & 1) ^ oddoeven)) {
+                            digit *= 2;
+                            if (digit > 9) digit -= 9;
+                        };
+                        sum += digit;
+                    };
+                    if (sum == 0) return false;
+                    if (sum % 10 == 0) return true;
+                };
+                return false;
+            }
+
+            function isLuhnNum(argvalue) {
+                argvalue = argvalue.toString();
+                if (argvalue.length == 0) {
+                    return false;
+                }
+                for (var n = 0; n < argvalue.length; n++) {
+                    if ((argvalue.substring(n, n+1) < "0") ||
+                        (argvalue.substring(n,n+1) > "9")) {
+                        return false;
+                    }
+                }
+                return true;
+            }]]>
+         </javascript>
+
+      </validator>
+
+
+      <validator name="email"
+            classname="org.apache.commons.validator.GenericValidator"
+               method="isEmail"
+         methodParams="java.lang.String"
+              depends=""
+                  msg="errors.email">
+
+         <javascript><![CDATA[
+            function validateEmail(form) {
+                var bValid = true;
+                var focusField = null;
+                var i = 0;
+                var fields = new Array();
+                oEmail = new email();
+                for (x in oEmail) {
+                    if ((form[oEmail[x][0]].type == 'text' ||
+                         form[oEmail[x][0]].type == 'textarea') &&
+                        (form[oEmail[x][0]].value.length > 0)) {
+                        if (!checkEmail(form[oEmail[x][0]].value)) {
+                            if (i == 0) {
+                                focusField = form[oEmail[x][0]];
+                            }
+                            fields[i++] = oEmail[x][1];
+                            bValid = false;
+                        }
+                    }
+                }
+                if (fields.length > 0) {
+                    focusField.focus();
+                    alert(fields.join('\n'));
+                }
+                return bValid;
+            }
+
+            /**
+             * Reference: Sandeep V. Tamhankar ([EMAIL PROTECTED]),
+             * http://javascript.internet.com
+             */
+            function checkEmail(emailStr) {
+               if (emailStr.length == 0) {
+                   return true;
+               }
+               var emailPat=/^(.+)@(.+)$/;
+               var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]";
+               var validChars="\[^\\s" + specialChars + "\]";
+               var quotedUser="(\"[^\"]*\")";
+               var 
ipDomainPat=/^(\d{1,3})[.](\d{1,3})[.](\d{1,3})[.](\d{1,3})$/;
+               var atom=validChars + '+';
+               var word="(" + atom + "|" + quotedUser + ")";
+               var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
+               var domainPat=new RegExp("^" + atom + "(\\." + atom + ")*$");
+               var matchArray=emailStr.match(emailPat);
+               if (matchArray == null) {
+                   return false;
+               }
+               var user=matchArray[1];
+               var domain=matchArray[2];
+               if (user.match(userPat) == null) {
+                   return false;
+               }
+               var IPArray = domain.match(ipDomainPat);
+               if (IPArray != null) {
+                   for (var i = 1; i <= 4; i++) {
+                      if (IPArray[i] > 255) {
+                         return false;
+                      }
+                   }
+                   return true;
+               }
+               var domainArray=domain.match(domainPat);
+               if (domainArray == null) {
+                   return false;
+               }
+               var atomPat=new RegExp(atom,"g");
+               var domArr=domain.match(atomPat);
+               var len=domArr.length;
+               if ((domArr[domArr.length-1].length < 2) ||
+                   (domArr[domArr.length-1].length > 3)) {
+                   return false;
+               }
+               if (len < 2) {
+                   return false;
+               }
+               return true;
+            }]]>
+         </javascript>
+
+      </validator>
+
+   </global>
+
+</form-validation>

Modified: struts/shale/trunk/use-cases/src/web/usecases.jsp
URL: 
http://svn.apache.org/viewcvs/struts/shale/trunk/use-cases/src/web/usecases.jsp?view=diff&r1=161824&r2=161825
==============================================================================
--- struts/shale/trunk/use-cases/src/web/usecases.jsp (original)
+++ struts/shale/trunk/use-cases/src/web/usecases.jsp Mon Apr 18 19:07:17 2005
@@ -123,6 +123,18 @@
 
   </h:panelGrid>
 
+  <h1><h:outputText     value="#{messages['usecases.validator']}"/></h1>
+
+  <h:panelGrid        columns="1">
+
+    <h:commandLink         id="validation"
+                       action="validate$test">
+      <h:outputText     value="#{messages['usecases.validate']}"/>
+    
+    </h:commandLink>
+
+  </h:panelGrid>
+
  </h:form>
 
 </body>

Added: struts/shale/trunk/use-cases/src/web/validator/test.jsp
URL: 
http://svn.apache.org/viewcvs/struts/shale/trunk/use-cases/src/web/validator/test.jsp?view=auto&rev=161825
==============================================================================
--- struts/shale/trunk/use-cases/src/web/validator/test.jsp (added)
+++ struts/shale/trunk/use-cases/src/web/validator/test.jsp Mon Apr 18 19:07:17 
2005
@@ -0,0 +1,172 @@
+<[EMAIL PROTECTED] contentType="text/html;charset=UTF-8"%>
+<%@ taglib prefix="f" uri="http://java.sun.com/jsf/core"; %>
+<%@ taglib prefix="h" uri="http://java.sun.com/jsf/html"; %>
+<%@ taglib prefix="s" uri="http://struts.apache.org/shale/core"; %>
+
+<%--
+
+ Copyright 2004-2005 The Apache Software Foundation.
+ 
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+ 
+      http://www.apache.org/licenses/LICENSE-2.0
+ 
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
+--%>
+
+<f:view>
+<[EMAIL PROTECTED]              file="../messages.jspf"%>
+<html>
+<head>
+<title>
+  <h:outputText        value="#{messages['validate.test.title']}"/>
+</title>
+</head>
+<body>
+
+  <h:form                 id="form" 
+                    onsubmit="return validateForm(this);">
+
+    <h:outputText      value="#{messages['validate.test.payment.heading']}"
+                       style="font-size: 1.2em;"/>
+    <p>
+    <h:panelGrid          id="grid"
+                     columns="3">
+
+      <h:outputLabel     for="amount"    
+                       value="#{messages['validate.test.amount']}"/>
+
+      <h:outputText value="#{messages['validate.test.currency.symbol']}"/>
+
+      <h:panelGroup>
+         <h:inputText     id="amount"
+                       value="#{validate$test.amount}"
+                        size="7">
+
+            <f:convertNumber 
+           minFractionDigits="2"/> 
+
+            <s:commonsValidator 
+                        type="required"
+                        arg="#{messages['validate.test.amount']}"
+                     server="false" 
+                     client="true"/>
+
+            <s:commonsValidator 
+                        type="floatRange"
+                         min="10" 
+                         max="1000" 
+                         arg="#{msgs.amount}"
+                      server="true" 
+                      client="false"/>
+
+         </h:inputText>
+
+         <h:message      for="amount"
+                       style="color: red; font-style: italic;"/>
+      </h:panelGroup>
+
+      <h:outputLabel     for="creditCard"    
+                       value="#{messages['prompt.creditCardNumber']}"/>
+
+      <h:outputText    value=""/>
+
+      <h:panelGroup>
+         <h:inputText     id="creditCard"
+                        size="11"
+                       value="#{validate$test.creditCard}"
+                    required="true">
+
+            <s:commonsValidator 
+                        type="required"
+                         arg="#{messages['prompt.creditCardNumber']}"
+                     server="false" 
+                     client="true"/>
+
+            <s:commonsValidator 
+                        type="creditCard"
+                         arg="#{messages['prompt.creditCardNumber']}"
+                      server="true" 
+                      client="false"/>
+
+            <s:commonsValidator type="mask" 
+                       mask="[4-6].*"
+                    
message="#{messages['validate.test.unknown.credit.card.type']}"
+                     server="false" 
+                     client="true"/>
+
+         </h:inputText>
+
+         <h:message      for="creditCard"
+                       style="color: red; font-style: italic;"/>
+      </h:panelGroup>
+
+      <h:outputText value="#{messages['prompt.expirationDate']}"/>
+
+      <h:outputText    value=""/>
+
+      <h:panelGroup>
+        <h:inputText     id="date"
+                      value="#{validate$test.expirationDate}">
+
+          <f:convertDateTime 
+                     pattern="MM/dd/yyyy"/>
+
+            <s:commonsValidator 
+                        type="required"
+                        arg="#{messages['prompt.expirationDate']}"
+                     server="false" 
+                     client="true"/>
+
+          <s:commonsValidator  
+                       type="date"
+          datePatternStrict="MM/dd/yyyy" 
+                    message="#{messages['validate.test.bad.expiration.date']}"
+                        arg="#{messages['prompt.expirationDate']}"
+                     server="false" 
+                     client="true"/> 
+
+       </h:inputText>
+       
+       <h:message       for="date"
+                       style="color: red; font-style: italic;"/>
+
+      </h:panelGroup>
+
+      <h:outputText    value=""/>
+      <h:outputText    value=""/>
+      <h:outputText    value=""/>
+
+      <h:commandButton value="Submit"
+                      action="validate$thankYou"/>
+
+    </h:panelGrid>
+
+        <f:verbatim><p></f:verbatim>
+
+        <h:outputText     value="#{messages['validate.test.description']}"
+                         escape="false"
+                          style="font-style: italic"/>
+
+    <f:verbatim><p></f:verbatim>
+
+   <h:commandLink 
+                 immediate="true"  
+                     value="Use cases top-level menu"
+                    action="usecases$toplevel"/>
+
+    <s:validatorScript 
+                   functionName="validateForm"/>
+
+  </h:form>
+
+</body>
+</html>
+</f:view>

Added: struts/shale/trunk/use-cases/src/web/validator/thankYou.jsp
URL: 
http://svn.apache.org/viewcvs/struts/shale/trunk/use-cases/src/web/validator/thankYou.jsp?view=auto&rev=161825
==============================================================================
--- struts/shale/trunk/use-cases/src/web/validator/thankYou.jsp (added)
+++ struts/shale/trunk/use-cases/src/web/validator/thankYou.jsp Mon Apr 18 
19:07:17 2005
@@ -0,0 +1,98 @@
+<[EMAIL PROTECTED] contentType="text/html;charset=UTF-8"%>
+<%@ taglib prefix="f" uri="http://java.sun.com/jsf/core"; %>
+<%@ taglib prefix="h" uri="http://java.sun.com/jsf/html"; %>
+<%@ taglib prefix="s" uri="http://struts.apache.org/shale/core"; %>
+
+<%--
+
+ Copyright 2004-2005 The Apache Software Foundation.
+ 
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+ 
+      http://www.apache.org/licenses/LICENSE-2.0
+ 
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
+--%>
+
+<f:view>
+<[EMAIL PROTECTED]              file="../messages.jspf"%>
+<html>
+<head>
+<title>
+  <h:outputText        value="#{messages['validate.test.thank.you.title']}"/>
+</title>
+</head>
+<body>
+
+  <h:form                 id="form"> 
+
+    <h:outputText      
value="#{messages['validate.test.payment.thank.you.heading']}"
+                       style="font-size: 1.2em;"/>
+    <p>
+    <h:panelGrid          id="grid"
+                     columns="3">
+
+      <h:outputLabel     for="amount"    
+                       value="#{messages['validate.test.amount']}"/>
+
+      <h:outputText    value="#{messages['validate.test.currency.symbol']}"/>
+
+      <h:outputText       id="amount"
+                       value="#{validate$test.amount}">
+
+            <f:convertNumber 
+           minFractionDigits="2"/> 
+
+      </h:outputText>
+
+
+      <h:outputLabel     for="creditCard"    
+                       value="#{messages['prompt.creditCardNumber']}"/>
+
+      <h:outputText    value=""/>
+
+      <h:outputText       id="creditCard"
+                       value="#{validate$test.creditCard}">
+
+      </h:outputText>
+
+      <h:outputText    value="#{messages['prompt.expirationDate']}"/>
+
+      <h:outputText    value=""/>
+
+      <h:outputText       id="date"
+                       value="#{validate$test.expirationDate}">
+
+          <f:convertDateTime 
+                     pattern="MM/dd/yyyy"/>
+
+       </h:outputText>
+     
+    </h:panelGrid>
+      
+    <h:panelGrid columns="1">
+       <h:commandButton   
+                       value="Back"
+                      action="validate$test"/>
+
+       <f:verbatim><p></f:verbatim>
+
+       <h:commandLink   
+                       value="Use cases top-level menu"
+                      action="usecases$toplevel"/>
+    </h:panelGrid>
+
+    <s:validatorScript functionName="validateForm"/>
+
+  </h:form>
+
+</body>
+</html>
+</f:view>



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to