struts-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From craig...@apache.org
Subject cvs commit: jakarta-struts/conf/share validator-rules.xml
Date Sun, 14 Jul 2002 01:33:04 GMT
craigmcc    2002/07/13 18:33:03

  Modified:    conf/share validator-rules.xml
  Log:
  Cosmetic changes only (line endings, spacing, code formatting to standards,
  and so on) -- there should be no functional changes.
  
  Revision  Changes    Path
  1.4       +1 -1      jakarta-struts/conf/share/validator-rules.xml
  
  Index: validator-rules.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-struts/conf/share/validator-rules.xml,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- validator-rules.xml	25 Jun 2002 01:01:13 -0000	1.3
  +++ validator-rules.xml	14 Jul 2002 01:33:03 -0000	1.4
  @@ -1 +1 @@
  -<!--

   This file contains the default Struts Validator pluggable validator 

   definitions.  It should be placed somewhere under /WEB-INF and 

   referenced in the struts-config.xml under the plug-in element 

   for the ValidatorPlugIn.



      <plug-in className="org.apache.struts.validator.ValidatorPlugIn">

        <set-property property="pathnames" value="/WEB-INF/validator-rules.xml,
                                                   /WEB-INF/validation.xml"/>

      </plug-in>

   

   These are the default error messages associated with        

   each validator defined in this file.  They should be        

   added to your projects ApplicationResources.properties      

   file or you can associate new ones by modifying the         

   pluggable validators msg attributes in this file.           

   

   # Struts Validator Error Messages

   errors.required={0} is required.

   errors.minlength={0} can not be less than {1} characters.

   errors.maxlength={0} can not be greater than {1} characters.

   errors.invalid={0} is invalid.

   

   errors.byte={0} must be an byte.

   errors.short={0} must be an short.

   errors.integer={0} must be an integer.

   errors.long={0} must be an long.

   errors.float={0} must be an float.

   errors.double={0} must be an double.

   

   errors.date={0} is not a date.

   errors.range={0} is not in the range {1} through {2}.

   errors.creditcard={0} is not a valid credit card number.

   errors.email={0} is an invalid e-mail address.



-->

<form-validation>

   <global>

      <validator name="required"

                 classname="org.apache.struts.util.StrutsValidator"

                 method="validateRequired"

                 methodParams="java.lang.Object,

                               org.apache.commons.validator.ValidatorAction,

                               org.apache.commons.validator.Field,

                               org.apache.struts.action.ActionErrors,

                               javax.servlet.http.HttpServletRequest"

                 msg="errors.required">

         <javascript><![CDATA[

            function validateRequired(form) {                                                                       

                var bValid = true;

                var focusField = null;

                var i = 0;                                                                                          

                var fields = new Array();                                                                           

                oRequired = new required();                                                                         

                                                                                                                    

                for (x in oRequired) {                                                                              

                    if ((form[oRequired[x][0]].type == 'text' || form[oRequired[x][0]].type == 'textarea' || form[oRequired[x][0]].type == 'select-one' || form[oRequired[x][0]].type == 'radio' || form[oRequired[x][0]].type == 'password') && form[oRequired[x][0]].value == '') {

                       if (i == 0)

                          focusField = form[oRequired[x][0]]; 

                          

                       fields[i++] = oRequired[x][1];

                        

                       bValid = false;                                                                             

                    }                                                                                               

                }                                                                                                   

                                                                                                                   

                if (fields.length > 0) {

                   focusField.focus();

                   alert(fields.join('\n'));                                                                      

                }                                                                                                   

                                                                                                                   

                return bValid;                                                                                      

            }]]>

         </javascript>

      </validator>



      <validator name="minlength"

                 classname="org.apache.struts.util.StrutsValidator"

                 method="validateMinLength"

                 methodParams="java.lang.Object,

                               org.apache.commons.validator.ValidatorAction,

                               org.apache.commons.validator.Field,

                               org.apache.struts.action.ActionErrors,

                               javax.servlet.http.HttpServletRequest"

                 depends="required"

                 msg="errors.minlength">

         <javascript><![CDATA[

            function validateMinLength(form) {                                                                                                    

                var bValid = true;

                var focusField = null;

                var i = 0;                                                                                                                    

                var fields = new Array();                                                                                                     

                oMinLength = new minlength();                                                                                                        

                                                                                                                                              

                for (x in oMinLength) {                                                                                                          

                    if (form[oMinLength[x][0]].type == 'text' || form[oMinLength[x][0]].type == 'textarea') {   

                       var iMin = parseInt(oMinLength[x][2]("minlength"));

            

                       if (!(form[oMinLength[x][0]].value.length >= iMin)) {

                          if (i == 0)

                             focusField = form[oMinLength[x][0]]; 

            

                          fields[i++] = oMinLength[x][1];

            

                          bValid = false;                                                                                                     

                       }                                                                                                                      

                    }                                                                                                                         

                }                                                                                                                             

                                                                                                                                              

                if (fields.length > 0) {

                   focusField.focus();

                   alert(fields.join('\n'));                                                                                                  

                }                                                                                                                             

                                                                                                                                              

                return bValid;                                                                                                                

            }]]>

         </javascript>

      </validator>



      <validator name="maxlength"

                 classname="org.apache.struts.util.StrutsValidator"

                 method="validateMaxLength"

                 methodParams="java.lang.Object,

                               org.apache.commons.validator.ValidatorAction,

                               org.apache.commons.validator.Field,

                               org.apache.struts.action.ActionErrors,

                               javax.servlet.http.HttpServletRequest"

                 depends="required"

                 msg="errors.maxlength">

         <javascript><![CDATA[

            function validateMaxLength(form) {                                                                                                    

                var bValid = true;

                var focusField = null;

                var i = 0;                                                                                                                    

                var fields = new Array();                                                                                                     

                oMaxLength = new maxlength();                                                                                                        

                                                                                                                                              

                for (x in oMaxLength) {                                                                                                          

                    if (form[oMaxLength[x][0]].type == 'text' || form[oMaxLength[x][0]].type == 'textarea') {   

                       var iMax = parseInt(oMaxLength[x][2]("maxlength"));

            

                       if (!(form[oMaxLength[x][0]].value.length <= iMax)) {

                          if (i == 0)

                             focusField = form[oMaxLength[x][0]]; 

            

                          fields[i++] = oMaxLength[x][1];

            

                          bValid = false;                                                                                                     

                       }                                                                                                                      

                    }                                                                                                                         

                }                                                                                                                             

                                                                                                                                              

                if (fields.length > 0) {

                   focusField.focus();

                   alert(fields.join('\n'));                                                                                                  

                }                                                                                                                             

                                                                                                                                              

                return bValid;                                                                                                                

            }]]>

         </javascript>

      </validator>



      <validator name="mask"

                 classname="org.apache.struts.util.StrutsValidator"

                 method="validateMask"

                 methodParams="java.lang.Object,

                               org.apache.commons.validator.ValidatorAction,

                               org.apache.commons.validator.Field,

                               org.apache.struts.action.ActionErrors,

                               javax.servlet.http.HttpServletRequest"

                 depends="required"

                 msg="errors.invalid">

         <javascript><![CDATA[

            function validateMask(form) {                                                                                                    

                var bValid = true;

                var focusField = null;

                var i = 0;                                                                                                                    

                var fields = new Array();                                                                                                     

                oMasked = new mask();                                                                                                        

                                                                                                                                              

                for (x in oMasked) {                                                                                                          

                    if ((form[oMasked[x][0]].type == 'text' || form[oMasked[x][0]].type == 'textarea' || form[oMasked[x][0]].type == 'password') && form[oMasked[x][0]].value.length > 0) {   

                       if (!matchPattern(form[oMasked[x][0]].value, oMasked[x][2]("mask"))) {

                          if (i == 0)

                             focusField = form[oMasked[x][0]]; 

            

                          fields[i++] = oMasked[x][1];

                          bValid = false;                                                                                                     

                       }                                                                                                                      

                    }                                                                                                                         

                }                                                                                                                             

                                                                                                                                              

                if (fields.length > 0) {

                   focusField.focus();

                   alert(fields.join('\n'));                                                                                                  

                }                                                                                                                             

                                                                                                                                              

                return bValid;                                                                                                                

            }                                                                                                                                 

                                                                                                                                              

            function matchPattern(value, mask) {

               var bMatched = mask.exec(value);

                                                                                                                                              

               if(!bMatched) {                                                                                                                

                  return false;                                                                                                               

               }                                                                                                                              

                                                                                                                                              

               return true;                                                                                                                   

            }]]>

         </javascript>

      </validator>



      <validator name="byte"

                 classname="org.apache.struts.util.StrutsValidator"

                 method="validateByte"

                 methodParams="java.lang.Object,

                               org.apache.commons.validator.ValidatorAction,

                               org.apache.commons.validator.Field,

                               org.apache.struts.action.ActionErrors,

                               javax.servlet.http.HttpServletRequest"

                 depends="required"

                 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) {                                                                              

                    if ((form[oByte[x][0]].type == 'text' || form[oByte[x][0]].type == 'textarea' || form[oByte[x][0]].type == 'select-one' || form[oByte[x][0]].type == 'radio') && form[oByte[x][0]].value.length > 0) {   

                       var iValue = parseInt(form[oByte[x][0]].value);

            

                       if (!iValue || !(iValue >= -128 && iValue <= 127)) {

                          if (i == 0)

                             focusField = form[oByte[x][0]]; 

                             

                          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.struts.util.StrutsValidator"

                 method="validateShort"

                 methodParams="java.lang.Object,

                               org.apache.commons.validator.ValidatorAction,

                               org.apache.commons.validator.Field,

                               org.apache.struts.action.ActionErrors,

                               javax.servlet.http.HttpServletRequest"

                 depends="required"

                 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) {                                                                              

                    if ((form[oShort[x][0]].type == 'text' || form[oShort[x][0]].type == 'textarea' || form[oShort[x][0]].type == 'select-one' || form[oShort[x][0]].type == 'radio') && form[oShort[x][0]].value.length > 0) {   

                       var iValue = parseInt(form[oShort[x][0]].value);

            

                       if (!iValue || !(iValue >= -32768 && iValue <= 32767)) {

                          if (i == 0)

                             focusField = form[oShort[x][0]]; 

                             

                          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.struts.util.StrutsValidator"

                 method="validateInteger"

                 methodParams="java.lang.Object,

                               org.apache.commons.validator.ValidatorAction,

                               org.apache.commons.validator.Field,

                               org.apache.struts.action.ActionErrors,

                               javax.servlet.http.HttpServletRequest"

                 depends="required"

                 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) {                                                                              

                    if ((form[oInteger[x][0]].type == 'text' || form[oInteger[x][0]].type == 'textarea' || form[oInteger[x][0]].type == 'select-one' || form[oInteger[x][0]].type == 'radio') && form[oInteger[x][0]].value.length > 0) {   

                       var iValue = parseInt(form[oInteger[x][0]].value);

            

                       if (!iValue || !(iValue >= -2147483648 && iValue <= 2147483647)) {

                          if (i == 0)

                             focusField = form[oInteger[x][0]]; 

                             

                          fields[i++] = oInteger[x][1];

                           

                          bValid = false;

                       }

                    }                                                                                               

                }                                                                                                   

            

                if (fields.length > 0) {

                   focusField.focus();

                   alert(fields.join('\n'));                                                                      

                }                                                                                                   

                                                                                                                   

                return bValid;                                                                                      

            }]]>

         </javascript>

      </validator>

      

      <validator name="long"

                 classname="org.apache.struts.util.StrutsValidator"

                 method="validateLong"

                 methodParams="java.lang.Object,

                               org.apache.commons.validator.ValidatorAction,

                               org.apache.commons.validator.Field,

                               org.apache.struts.action.ActionErrors,

                               javax.servlet.http.HttpServletRequest"

                 depends="required"

                 msg="errors.long"

      />

      <validator name="float"

                 classname="org.apache.struts.util.StrutsValidator"

                 method="validateFloat"

                 methodParams="java.lang.Object,

                               org.apache.commons.validator.ValidatorAction,

                               org.apache.commons.validator.Field,

                               org.apache.struts.action.ActionErrors,

                               javax.servlet.http.HttpServletRequest"

                 depends="required"

                 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) {                                                                              

                    if ((form[oFloat[x][0]].type == 'text' || form[oFloat[x][0]].type == 'textarea' || form[oFloat[x][0]].type == 'select-one' || form[oFloat[x][0]].type == 'radio') && form[oFloat[x][0]].value.length > 0) {   

                       var iValue = parseFloat(form[oFloat[x][0]].value);

            

                       if (!iValue) {

                          if (i == 0)

                             focusField = form[oFloat[x][0]]; 

                             

                          fields[i++] = oFloat[x][1];

                           

                          bValid = false;

                       }

                    }                                                                                               

                }                                                                                                   

            

                if (fields.length > 0) {

                   focusField.focus();

                   alert(fields.join('\n'));                                                                      

                }                                                                                                   

                                                                                                                   

                return bValid;                                                                                      

            }]]>

         </javascript>

      </validator>



      <validator name="double"

                 classname="org.apache.struts.util.StrutsValidator"

                 method="validateDouble"

                 methodParams="java.lang.Object,

                               org.apache.commons.validator.ValidatorAction,

                               org.apache.commons.validator.Field,

                               org.apache.struts.action.ActionErrors,

                               javax.servlet.http.HttpServletRequest"

                 depends="required"

                 msg="errors.double"/>



      <validator name="date"

                 classname="org.apache.struts.util.StrutsValidator"

                 method="validateDate"

                 methodParams="java.lang.Object,

                               org.apache.commons.validator.ValidatorAction,

                               org.apache.commons.validator.Field,

                               org.apache.struts.action.ActionErrors,

                               javax.servlet.http.HttpServletRequest"

                 depends="required"

                 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="range"

                 classname="org.apache.struts.util.StrutsValidator"

                 method="validateRange"

                 methodParams="java.lang.Object,

                               org.apache.commons.validator.ValidatorAction,

                               org.apache.commons.validator.Field,

                               org.apache.struts.action.ActionErrors,

                               javax.servlet.http.HttpServletRequest"

                 depends="required,integer"

                 msg="errors.range">

         <javascript><![CDATA[

            function validateRange(form) {                                                                                                    

                var bValid = true;

                var focusField = null;

                var i = 0;                                                                                                                    

                var fields = new Array();                                                                                                     

                oRange = new range();                                                                                                        

                                                                                                                                              

                for (x in oRange) {                                                                                                          

                    if ((form[oRange[x][0]].type == 'text' || form[oRange[x][0]].type == 'textarea') && form[oRange[x][0]].value.length > 0) {   

                       var iMin = parseInt(oRange[x][2]("min"));

                       var iMax = parseInt(oRange[x][2]("max"));

                       var iValue = parseInt(form[oRange[x][0]].value);

            

                       if (!(iValue >= iMin && iValue <= iMax)) {

                          if (i == 0)

                             focusField = form[oRange[x][0]]; 

            

                          fields[i++] = oRange[x][1];

            

                          bValid = false;                                                                                                     

                       }                                                                                                                      

                    }                                                                                                                         

                }                                                                                                                             

                                                                                                                                              

                if (fields.length > 0) {

                   focusField.focus();

                   alert(fields.join('\n'));                                                                                                  

                }                                                                                                                             

                                                                                                                                              

                return bValid;                                                                                                                

            }]]>

         </javascript>

      </validator>



      <validator name="creditCard"

                 classname="org.apache.struts.util.StrutsValidator"

                 method="validateCreditCard"

                 methodParams="java.lang.Object,

                               org.apache.commons.validator.ValidatorAction,

                               org.apache.commons.validator.Field,

                               org.apache.struts.action.ActionErrors,

                               javax.servlet.http.HttpServletRequest"

                 depends="required"

                 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.struts.util.StrutsValidator"

                 method="validateEmail"

                 methodParams="java.lang.Object,

                               org.apache.commons.validator.ValidatorAction,

                               org.apache.commons.validator.Field,

                               org.apache.struts.action.ActionErrors,

                               javax.servlet.http.HttpServletRequest"

                 depends="required"

                 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 (stamhankar@hotmail.com), 

             * 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>

  \ No newline at end of file
  +<!--

   This file contains the default Struts Validator pluggable validator 
   definitions.  It should be placed somewhere under /WEB-INF and 
   referenced in the struts-config.xml under the plug-in element 
   for the ValidatorPlugIn.

      <plug-in className="org.apache.struts.validator.ValidatorPlugIn">
        <set-property property="pathnames" value="/WEB-INF/validator-rules.xml,
                                                  /WEB-INF/validation.xml"/>
      </plug-in>

   These are the default error messages associated with        
   each validator defined in this file.  They should be        
   added to your projects ApplicationResources.properties      
   file or you can associate new ones by modifying the         
   pluggable validators msg attributes in this file.           
   
   # Struts Validator Error Messages
   errors.required={0} is required.
   errors.minlength={0} can not be less than {1} characters.
   errors.maxlength={0} can not be greater than {1} characters.
   errors.invalid={0} is invalid.
   
   errors.byte={0} must be an byte.
   errors.short={0} must be an short.
   errors.integer={0} must be an integer.
   errors.long={0} must be an long.
   errors.float={0} must be an float.
   errors.double={0} must be an double.
   
   errors.date={0} is not a date.
   errors.range={0} is not in the range {1} through {2}.
   errors.creditcard={0} is not a valid credit card number.
   errors.email={0} is an invalid e-mail address.

-->

<form-validation>

   <global>

      <validator name="required"
            classname="org.apache.struts.util.StrutsValidator"
               method="validateRequired"
         methodParams="java.lang.Object,
                       org.apache.commons.validator.ValidatorAction,
                       org.apache.commons.validator.Field,
                       org.apache.struts.action.ActionErrors,
                       javax.servlet.http.HttpServletRequest"
                  msg="errors.required">

         <javascript><![CDATA[
            function validateRequired(form) {
                var bValid = true;
                var focusField = null;
                var i = 0;
                var fields = new Array();
                oRequired = new required();
                for (x in oRequired) {
                    if ((form[oRequired[x][0]].type == 'text' ||
                         form[oRequired[x][0]].type == 'textarea' ||
                         form[oRequired[x][0]].type == 'select-one' ||
                         form[oRequired[x][0]].type == 'radio' ||
                         form[oRequired[x][0]].type == 'password') &&
                        (form[oRequired[x][0]].value == '')) {
                        if (i == 0) {
                            focusField = form[oRequired[x][0]];
                        }
                        fields[i++] = oRequired[x][1];
                        bValid = false;
                    }
                }
                if (fields.length > 0) {
                   focusField.focus();
                   alert(fields.join('\n'));
                }
                return bValid;
            }]]>
         </javascript>

      </validator>


      <validator name="minlength"
            classname="org.apache.struts.util.StrutsValidator"
               method="validateMinLength"
         methodParams="java.lang.Object,
                       org.apache.commons.validator.ValidatorAction,
                       org.apache.commons.validator.Field,
                       org.apache.struts.action.ActionErrors,
                       javax.servlet.http.HttpServletRequest"
              depends="required"
                  msg="errors.minlength">

         <javascript><![CDATA[
            function validateMinLength(form) {
                var bValid = true;
                var focusField = null;
                var i = 0;
                var fields = new Array();
                oMinLength = new minlength();
                for (x in oMinLength) {
                    if (form[oMinLength[x][0]].type == 'text' ||
                        form[oMinLength[x][0]].type == 'textarea') {
                        var iMin = parseInt(oMinLength[x][2]("minlength"));
                        if (!(form[oMinLength[x][0]].value.length >= iMin)) {
                            if (i == 0) {
                                focusField = form[oMinLength[x][0]];
                            }
                            fields[i++] = oMinLength[x][1];
                            bValid = false;
                        }
                    }
                }
                if (fields.length > 0) {
                   focusField.focus();
                   alert(fields.join('\n'));
                }
                return bValid;
            }]]>
         </javascript>

      </validator>


      <validator name="maxlength"
            classname="org.apache.struts.util.StrutsValidator"
               method="validateMaxLength"
         methodParams="java.lang.Object,
                       org.apache.commons.validator.ValidatorAction,
                       org.apache.commons.validator.Field,
                       org.apache.struts.action.ActionErrors,
                       javax.servlet.http.HttpServletRequest"
              depends="required"
                  msg="errors.maxlength">

         <javascript><![CDATA[
            function validateMaxLength(form) {
                var bValid = true;
                var focusField = null;
                var i = 0;
                var fields = new Array();
                oMaxLength = new maxlength();
                for (x in oMaxLength) {
                    if (form[oMaxLength[x][0]].type == 'text' ||
                        form[oMaxLength[x][0]].type == 'textarea') {
                        var iMax = parseInt(oMaxLength[x][2]("maxlength"));
                        if (!(form[oMaxLength[x][0]].value.length <= iMax)) {
                            if (i == 0) {
                                focusField = form[oMaxLength[x][0]];
                            }
                            fields[i++] = oMaxLength[x][1];
                            bValid = false;
                        }
                    }
                }
                if (fields.length > 0) {
                   focusField.focus();
                   alert(fields.join('\n'));
                }
                return bValid;
            }]]>
         </javascript>

      </validator>


      <validator name="mask"
            classname="org.apache.struts.util.StrutsValidator"
               method="validateMask"
         methodParams="java.lang.Object,
                       org.apache.commons.validator.ValidatorAction,
                       org.apache.commons.validator.Field,
                       org.apache.struts.action.ActionErrors,
                       javax.servlet.http.HttpServletRequest"
              depends="required"
                  msg="errors.invalid">

         <javascript><![CDATA[
            function validateMask(form) {
                var bValid = true;
                var focusField = null;
                var i = 0;
                var fields = new Array();
                oMasked = new mask();
                for (x in oMasked) {
                    if ((form[oMasked[x][0]].type == 'text' ||
                         form[oMasked[x][0]].type == 'textarea' ||
                         form[oMasked[x][0]].type == 'password') &&
                        (form[oMasked[x][0]].value.length > 0)) {
                        if (!matchPattern(form[oMasked[x][0]].value, oMasked[x][2]("mask"))) {
                            if (i == 0) {
                                focusField = form[oMasked[x][0]];
                            }
                            fields[i++] = oMasked[x][1];
                            bValid = false;
                        }
                    }
                }
                if (fields.length > 0) {
                   focusField.focus();
                   alert(fields.join('\n'));
                }
                return bValid;
            }

            function matchPattern(value, mask) {
               var bMatched = mask.exec(value);
               if (!bMatched) {
                   return false;
               }
               return true;
            }]]>
         </javascript>

      </validator>


      <validator name="byte"
            classname="org.apache.struts.util.StrutsValidator"
               method="validateByte"
         methodParams="java.lang.Object,
                       org.apache.commons.validator.ValidatorAction,
                       org.apache.commons.validator.Field,
                       org.apache.struts.action.ActionErrors,
                       javax.servlet.http.HttpServletRequest"
              depends="required"
                  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) {
                    if ((form[oByte[x][0]].type == 'text' ||
                         form[oByte[x][0]].type == 'textarea' ||
                         form[oByte[x][0]].type == 'select-one' ||
                         form[oByte[x][0]].type == 'radio') &&
                        (form[oByte[x][0]].value.length > 0)) {
                        var iValue = parseInt(form[oByte[x][0]].value);
                        if (!iValue || !(iValue >= -128 && iValue <= 127)) {
                            if (i == 0)
                                focusField = form[oByte[x][0]]; 
                            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.struts.util.StrutsValidator"
               method="validateShort"
         methodParams="java.lang.Object,
                       org.apache.commons.validator.ValidatorAction,
                       org.apache.commons.validator.Field,
                       org.apache.struts.action.ActionErrors,
                       javax.servlet.http.HttpServletRequest"
              depends="required"
                  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) {
                    if ((form[oShort[x][0]].type == 'text' ||
                         form[oShort[x][0]].type == 'textarea' ||
                         form[oShort[x][0]].type == 'select-one' ||
                         form[oShort[x][0]].type == 'radio') &&
                        (form[oShort[x][0]].value.length > 0)) {   
                        var iValue = parseInt(form[oShort[x][0]].value);
                        if (!iValue || !(iValue >= -32768 && iValue <= 32767)) {
                            if (i == 0) {
                                focusField = form[oShort[x][0]];
                            }
                            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.struts.util.StrutsValidator"
               method="validateInteger"
         methodParams="java.lang.Object,
                       org.apache.commons.validator.ValidatorAction,
                       org.apache.commons.validator.Field,
                       org.apache.struts.action.ActionErrors,
                       javax.servlet.http.HttpServletRequest"
              depends="required"
                  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) {
                    if ((form[oInteger[x][0]].type == 'text' ||
                         form[oInteger[x][0]].type == 'textarea' ||
                         form[oInteger[x][0]].type == 'select-one' ||
                         form[oInteger[x][0]].type == 'radio') &&
                        (form[oInteger[x][0]].value.length > 0)) {
                        var iValue = parseInt(form[oInteger[x][0]].value);
                        if (!iValue || !(iValue >= -2147483648 && iValue <= 2147483647)) {
                            if (i == 0) {
                                focusField = form[oInteger[x][0]];
                            }
                            fields[i++] = oInteger[x][1];
                            bValid = false;
                       }
                    }
                }
                if (fields.length > 0) {
                   focusField.focus();
                   alert(fields.join('\n'));
                }
                return bValid;
            }]]>
         </javascript>

      </validator>


      <validator name="long"
            classname="org.apache.struts.util.StrutsValidator"
               method="validateLong"
         methodParams="java.lang.Object,
                       org.apache.commons.validator.ValidatorAction,
                       org.apache.commons.validator.Field,
                       org.apache.struts.action.ActionErrors,
                       javax.servlet.http.HttpServletRequest"
              depends="required"
                  msg="errors.long"/>


      <validator name="float"
            classname="org.apache.struts.util.StrutsValidator"
               method="validateFloat"
         methodParams="java.lang.Object,
                       org.apache.commons.validator.ValidatorAction,
                       org.apache.commons.validator.Field,
                       org.apache.struts.action.ActionErrors,
                       javax.servlet.http.HttpServletRequest"
              depends="required"
                  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) {
                    if ((form[oFloat[x][0]].type == 'text' ||
                         form[oFloat[x][0]].type == 'textarea' ||
                         form[oFloat[x][0]].type == 'select-one' ||
                         form[oFloat[x][0]].type == 'radio') &&
                        (form[oFloat[x][0]].value.length > 0)) {   
                        var iValue = parseFloat(form[oFloat[x][0]].value);
                        if (!iValue) {
                            if (i == 0) {
                                focusField = form[oFloat[x][0]];
                            }
                            fields[i++] = oFloat[x][1];
                            bValid = false;
                        }
                    }
                }
                if (fields.length > 0) {
                   focusField.focus();
                   alert(fields.join('\n'));
                }
                return bValid;
            }]]>
         </javascript>

      </validator>


      <validator name="double"
            classname="org.apache.struts.util.StrutsValidator"
               method="validateDouble"
         methodParams="java.lang.Object,
                       org.apache.commons.validator.ValidatorAction,
                       org.apache.commons.validator.Field,
                       org.apache.struts.action.ActionErrors,
                       javax.servlet.http.HttpServletRequest"
              depends="required"
                  msg="errors.double"/>


      <validator name="date"
            classname="org.apache.struts.util.StrutsValidator"
               method="validateDate"
         methodParams="java.lang.Object,
                       org.apache.commons.validator.ValidatorAction,
                       org.apache.commons.validator.Field,
                       org.apache.struts.action.ActionErrors,
                       javax.servlet.http.HttpServletRequest"
              depends="required"
                  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="range"
            classname="org.apache.struts.util.StrutsValidator"
               method="validateRange"
         methodParams="java.lang.Object,
                       org.apache.commons.validator.ValidatorAction,
                       org.apache.commons.validator.Field,
                       org.apache.struts.action.ActionErrors,
                       javax.servlet.http.HttpServletRequest"
              depends="required,integer"
                  msg="errors.range">

         <javascript><![CDATA[
            function validateRange(form) {
                var bValid = true;
                var focusField = null;
                var i = 0;
                var fields = new Array();
                oRange = new range();
                for (x in oRange) {
                    if ((form[oRange[x][0]].type == 'text' ||
                         form[oRange[x][0]].type == 'textarea') &&
                        (form[oRange[x][0]].value.length > 0)) {
                        var iMin = parseInt(oRange[x][2]("min"));
                        var iMax = parseInt(oRange[x][2]("max"));
                        var iValue = parseInt(form[oRange[x][0]].value);
                        if (!(iValue >= iMin && iValue <= iMax)) {
                            if (i == 0) {
                                focusField = form[oRange[x][0]];
                            }
                            fields[i++] = oRange[x][1];
                            bValid = false;
                        }
                    }
                }
                if (fields.length > 0) {
                    focusField.focus();
                    alert(fields.join('\n'));
                }
                return bValid;
            }]]>
         </javascript>

      </validator>


      <validator name="creditCard"
            classname="org.apache.struts.util.StrutsValidator"
               method="validateCreditCard"
         methodParams="java.lang.Object,
                       org.apache.commons.validator.ValidatorAction,
                       org.apache.commons.validator.Field,
                       org.apache.struts.action.ActionErrors,
                       javax.servlet.http.HttpServletRequest"
              depends="required"
                  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.struts.util.StrutsValidator"
               method="validateEmail"
         methodParams="java.lang.Object,
                       org.apache.commons.validator.ValidatorAction,
                       org.apache.commons.validator.Field,
                       org.apache.struts.action.ActionErrors,
                       javax.servlet.http.HttpServletRequest"
              depends="required"
                  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 (stamhankar@hotmail.com),
             * 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>

  \ No newline at end of file
  
  
  

--
To unsubscribe, e-mail:   <mailto:struts-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:struts-dev-help@jakarta.apache.org>


Mime
View raw message