On 15 Jan 2002 [EMAIL PROTECTED] wrote:
> Date: 15 Jan 2002 06:25:00 -0000
> From: [EMAIL PROTECTED]
> Reply-To: Struts Developers List <[EMAIL PROTECTED]>
> To: [EMAIL PROTECTED]
> Subject: cvs commit: jakarta-struts/contrib/validator/web/example/WEB-INF
> validation.xml web.xml
>
> dwinterfeldt 02/01/14 22:24:59
>
> Modified: contrib/validator INSTALL build.properties.sample build.xml
> contrib/validator/docs index.html installation.html
> revision.html todolist.html
> contrib/validator/src/share/org/apache/struts/validator/action
> ValidatorServlet.java
> contrib/validator/web/example/WEB-INF validation.xml web.xml
> Added: contrib/validator/dist validator-rules.xml
> Log:
> Updated ValidatorServlet, docs, and example to allow validator rules to be stored
>and loaded in a separate file.
>
> Revision Changes Path
> 1.3 +4 -0 jakarta-struts/contrib/validator/INSTALL
>
> Index: INSTALL
> ===================================================================
> RCS file: /home/cvs/jakarta-struts/contrib/validator/INSTALL,v
> retrieving revision 1.2
> retrieving revision 1.3
> diff -u -r1.2 -r1.3
> --- INSTALL 15 Jan 2002 03:57:40 -0000 1.2
> +++ INSTALL 15 Jan 2002 06:24:59 -0000 1.3
> @@ -9,6 +9,10 @@
> <servlet>
> <servlet-name>validator</servlet-name>
> <servlet-class>org.apache.struts.action.ValidatorServlet</servlet-class>
> + <init-param>
> + <param-name>config-rules</param-name>
> + <param-value>/WEB-INF/validator-rules.xml</param-value>
> + </init-param>
> <init-param>
> <param-name>config</param-name>
> <param-value>/WEB-INF/validation.xml</param-value>
>
>
>
> 1.4 +21 -0 jakarta-struts/contrib/validator/build.properties.sample
>
> Index: build.properties.sample
> ===================================================================
> RCS file: /home/cvs/jakarta-struts/contrib/validator/build.properties.sample,v
> retrieving revision 1.3
> retrieving revision 1.4
> diff -u -r1.3 -r1.4
> --- build.properties.sample 15 Jan 2002 04:00:35 -0000 1.3
> +++ build.properties.sample 15 Jan 2002 06:24:59 -0000 1.4
> @@ -1,12 +1,33 @@
> # Properties related to the user's environment.
>
> +
> +# The JAR file containing a recent nightly build of the Validator package
> +# from the Jakarta Commons project.
>
>commons-validator.jar=d:/office/jakarta-commons/validator/dist/commons-validator.jar
> +
> +# The JAR file containing version 1.0 (or later) of the Beanutils package
> +# from the Jakarta Commons project.
> commons-beanutils.jar=d:/java/lib/commons-beanutils.jar
> +
> +# The JAR file containing version 1.0 (or later) of the Collections package
> +# from the Jakarta Commons project.
> commons-collections.jar=d:/java/lib/commons-collections.jar
> +
> +# The JAR file containing version 1.0 (or later) of the Digester package
> +# from the Jakarta Commons project.
> commons-digester.jar=d:/java/lib/commons-digester.jar
> +
> +# The JAR file containing version 1.0 (or later) of the Logging package
> +# from the Jakarta Commons project.
> +commons-logging.jar=e:/software/commons-logging/commons-logging.jar
> +
> struts.jar=d:/office/struts/jakarta-struts/target/library/struts.jar
> struts.tlds=d:/office/struts/jakarta-struts/target/library
> +
> +# The JAR file containing the Servlet API classes to compile against (either
> +# version 2.2 or 2.3)
> servlet.jar=e:/tomcat3/lib/servlet.jar
> +
> jdbc20ext.jar=d:/java/lib/jdbc2_0-stdext.jar
> regexp.jar=e:/software/regexp/jakarta-regexp-1.2.jar
> xerces.jar=e:/software/xerces/xerces.jar
>
>
>
> 1.5 +12 -7 jakarta-struts/contrib/validator/build.xml
>
> Index: build.xml
> ===================================================================
> RCS file: /home/cvs/jakarta-struts/contrib/validator/build.xml,v
> retrieving revision 1.4
> retrieving revision 1.5
> diff -u -r1.4 -r1.5
> --- build.xml 15 Jan 2002 03:54:45 -0000 1.4
> +++ build.xml 15 Jan 2002 06:24:59 -0000 1.5
> @@ -24,8 +24,9 @@
> <property name="build.javadocs" value="${dist}/${docs}/api" />
> <property name="package.root" value="org/apache/struts/validator"/>
> <property name="package.example" value="${package.root}/example"/>
> + <property name="default.validator.rules" value="${dist}/validator-rules.xml"/>
>
> - <target name="prepare">
> + <target name="prepare" description="Creates default directories">
> <!-- Create the time stamp -->
> <tstamp/>
> <!-- Create the build directory structure used by compile -->
> @@ -56,7 +57,7 @@
> <pathelement location="${xerces.jar}"/>
> </path>
>
> - <target name="compile" depends="prepare">
> + <target name="compile" depends="prepare" description="Compile distribution
>classes.">
> <!-- Compile the java code from ${src} into ${build} -->
> <javac srcdir="${src}/${share}"
> destdir="${build}">
> @@ -64,7 +65,7 @@
> </javac>
> </target>
>
> - <target name="jar" depends="compile">
> + <target name="jar" depends="compile" description="Create distribution jar.">
> <!-- Create the ${dist}/lib directory -->
> <mkdir dir="${dist}" />
>
> @@ -73,7 +74,7 @@
> basedir="${build}"/>
> </target>
>
> - <target name="compile_example" depends="jar">
> + <target name="compile_example" depends="jar" description="Compiles example
>classes">
> <!-- Compile the java code from ${src}/${example} into ${build} -->
> <javac srcdir="${src}/${example}"
> destdir="${target}/${example}/${web.classes}">
> @@ -81,7 +82,7 @@
> </javac>
> </target>
>
> - <target name="copy_example" depends="compile_example">
> + <target name="copy_example" depends="compile_example" description="Copies
>example files to target directory.">
> <copy todir="${target}/${example}/${web.classes}" >
> <fileset dir="${src}/${example}"
> excludes="**/*.java"
> @@ -98,7 +99,7 @@
>
> </target>
>
> - <target name="war" depends="copy_example">
> + <target name="war" depends="copy_example" description="Create example web app's
>war.">
> <mkdir dir="${webapps}" />
>
> <mkdir dir="lib" />
> @@ -107,8 +108,12 @@
> <copy file="${commons-beanutils.jar}" todir="lib"/>
> <copy file="${commons-collections.jar}" todir="lib"/>
> <copy file="${commons-digester.jar}" todir="lib"/>
> + <copy file="${commons-logging.jar}" todir="lib"/>
> <copy file="${regexp.jar}" todir="lib"/>
> -
> +
> + <!-- default validation rules -->
> + <copy file="${default.validator.rules}" todir="${target}/${example}/WEB-INF"/>
> +
> <copy todir="${target}/${example}" >
> <fileset dir="${web}/${example}">
> <include name="**/**" />
>
>
>
> 1.1 jakarta-struts/contrib/validator/dist/validator-rules.xml
>
> Index: validator-rules.xml
> ===================================================================
> <form-validation>
> <global>
> <validator name="required"
> classname="org.apache.struts.validator.util.StrutsValidator"
> method="validateRequired"
> 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.validator.util.StrutsValidator"
> method="validateMinLength"
> 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.validator.util.StrutsValidator"
> method="validateMaxLength"
> 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.validator.util.StrutsValidator"
> method="validateMask"
> 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.validator.util.StrutsValidator"
> method="validateByte"
> 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.validator.util.StrutsValidator"
> method="validateShort"
> 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.validator.util.StrutsValidator"
> method="validateInteger"
> 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.validator.util.StrutsValidator"
> method="validateLong"
> depends="required"
> msg="errors.long"
> />
> <validator name="float"
> classname="org.apache.struts.validator.util.StrutsValidator"
> method="validateFloat"
> 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.validator.util.StrutsValidator"
> method="validateDouble"
> depends="required"
> msg="errors.double"/>
>
> <validator name="date"
> classname="org.apache.struts.validator.util.StrutsValidator"
> method="validateDate"
> 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.validator.util.StrutsValidator"
> method="validateRange"
> 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.validator.util.StrutsValidator"
> method="validateCreditCard"
> 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.validator.util.StrutsValidator"
> method="validateEmail"
> 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 ([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>
>
>
>
> 1.5 +15 -13 jakarta-struts/contrib/validator/docs/index.html
>
> Index: index.html
> ===================================================================
> RCS file: /home/cvs/jakarta-struts/contrib/validator/docs/index.html,v
> retrieving revision 1.4
> retrieving revision 1.5
> diff -u -r1.4 -r1.5
> --- index.html 15 Jan 2002 03:55:34 -0000 1.4
> +++ index.html 15 Jan 2002 06:24:59 -0000 1.5
> @@ -49,9 +49,10 @@
> </td>
> <!-- Body -->
> <td valign="top">
> - <p>The Validation Framework was made to work with
> - <a href="http://jakarta.apache.org/struts">Struts</a> although it
>can be used to perform
> - validation on any JavaBean (by using the Validator class). It can
>perform basic
> + <p>The Validation Framework is now based on the Commons Validator
> + (<a
>href="http://jakarta.apache.org/commons">http://jakarta.apache.org/commons</a>).
> + Everything should work as it previously had with
> + <a href="http://jakarta.apache.org/struts">Struts</a>. It can
>perform basic
> validations to check if a field is required, matches a regular
>expression,
> email, credit card, and server side type checking and date
>validation. Different
> validation rules can be defined for different locales. The
>framework has basic support for
> @@ -60,28 +61,29 @@
> to the framework.
> </p>
> <p>
> - I wanted to mention that any type of validation can be performed in
>a validation
> - method. There seems to be a conception in some e-mails that the
>framework is only based on regular
> - expressions. They can do a lot so they are used almost exclusively
>in the examples, but the type
> - form shows validating some java primitives using standard java
>methods like Integer.parseInt,
> - validating a range, validating a credit card number, and validating
>a date.
> + There is an optional config-rules parameter that the
>ValdidatorServlet can take. This allows you
> + to store your validator rules (validator definitions) in a separate
>file. The standard file is
> + available in the dist directory and is named validator-rules.xml.
> </p>
> - <p>The Struts Validator is going to be incorporated into Struts 1.1.
>I'm working on finalizing
> - any design and/or feature issues before this occurs.<BR>
> - Note: The 7/2/2001 release is the last release
>build with Struts 1.0.
> - </p>
> <p>Feedback on bugs and suggestions are welcome.<BR>
> <a
>href="mailto:[EMAIL PROTECTED]">[EMAIL PROTECTED]</a>
> </p>
> <BR>
> <p>
> - <font size=-1>Update 1/13/2002</font><BR>
> + <font size=-1>Update 1/14/2002</font><BR>
> <ul>
> <li>Upgraded to use Commons Validator
>(http://jakarta.apache.org/commons).</li>
> <li>Packages changed to fall under
>org.apache.struts.validator.</li>
> <li>Documentation updated</li>
> <li>Custom JSP Tags except for JavascriptValidatorTag have been
>removed.</li>
> <li>GenericAction class and JDBC example have been removed.</li>
> + <li>
> + Added config-rules parameter to the ValidatorServlet so
>validation rules
> + could be stored in a separate xml file. The config parameter
>file
> + can still contain rules. The file specified by config-rules
>will be loaded
> + first so the file specified by config can define or override
>any validator
> + elements necessary.
> + </li>
> </ul>
> </p>
>
>
>
>
> 1.4 +4 -0 jakarta-struts/contrib/validator/docs/installation.html
>
> Index: installation.html
> ===================================================================
> RCS file: /home/cvs/jakarta-struts/contrib/validator/docs/installation.html,v
> retrieving revision 1.3
> retrieving revision 1.4
> diff -u -r1.3 -r1.4
> --- installation.html 15 Jan 2002 03:55:34 -0000 1.3
> +++ installation.html 15 Jan 2002 06:24:59 -0000 1.4
> @@ -59,6 +59,10 @@
> <servlet-name>validator</servlet-name>
> <BR>
>
><servlet-class>org.apache.struts.validator.action.ValidatorServlet</servlet-class>
> <BR>
> <init-param>
> <BR>
> +
><param-name>config-rules</param-name>
> <BR>
> +
><param-value>/WEB-INF/validator-rules.xml</param-value>
> <BR>
> + </init-param>
> <BR>
> + <init-param>
> <BR>
>
><param-name>config</param-name>
> <BR>
>
><param-value>/WEB-INF/validation.xml</param-value>
> <BR>
> </init-param>
> <BR>
>
>
>
> 1.6 +8 -1 jakarta-struts/contrib/validator/docs/revision.html
>
> Index: revision.html
> ===================================================================
> RCS file: /home/cvs/jakarta-struts/contrib/validator/docs/revision.html,v
> retrieving revision 1.5
> retrieving revision 1.6
> diff -u -r1.5 -r1.6
> --- revision.html 15 Jan 2002 03:55:34 -0000 1.5
> +++ revision.html 15 Jan 2002 06:24:59 -0000 1.6
> @@ -50,13 +50,20 @@
> <!-- Body -->
> <td valign="top">
> <H2>Revision Info</H2>
> - <font size=-1>Update 1/13/2002</font><BR>
> + <font size=-1>Update 1/14/2002</font><BR>
> <ul>
> <li>Upgraded to use Commons Validator
>(http://jakarta.apache.org/commons).</li>
> <li>Packages changed to fall under org.apache.struts.validator.</li>
> <li>Documentation updated</li>
> <li>Custom JSP Tags except for JavascriptValidatorTag have been
>removed.</li>
> <li>GenericAction class and JDBC example have been removed.</li>
> + <li>
> + Added config-rules parameter to the ValidatorServlet so
>validation rules
> + could be stored in a separate xml file. The config parameter
>file
> + can still contain rules. The file specified by config-rules
>will be loaded
> + first so the file specified by config can define or override
>any validator
> + elements necessary.
> + </li>
> </ul>
> <font size=-1>Update 10/18/2001 (using Struts 10/18/2001 source)</font><BR>
> <ul>
>
>
>
> 1.6 +1 -0 jakarta-struts/contrib/validator/docs/todolist.html
>
> Index: todolist.html
> ===================================================================
> RCS file: /home/cvs/jakarta-struts/contrib/validator/docs/todolist.html,v
> retrieving revision 1.5
> retrieving revision 1.6
> diff -u -r1.5 -r1.6
> --- todolist.html 15 Jan 2002 04:25:16 -0000 1.5
> +++ todolist.html 15 Jan 2002 06:24:59 -0000 1.6
> @@ -52,6 +52,7 @@
> <H2>To Do List</H2>
> <ul>
> <li>Have a way for indexed properties to work with
>JavascriptValidatorTag.</li>
> + <li>Fix bug in Javascript for select fields.</li>
> </ul>
> </td>
> <!-- / Body -->
>
>
>
> 1.2 +44 -11
>jakarta-struts/contrib/validator/src/share/org/apache/struts/validator/action/ValidatorServlet.java
>
> Index: ValidatorServlet.java
> ===================================================================
> RCS file:
>/home/cvs/jakarta-struts/contrib/validator/src/share/org/apache/struts/validator/action/ValidatorServlet.java,v
> retrieving revision 1.1
> retrieving revision 1.2
> diff -u -r1.1 -r1.2
> --- ValidatorServlet.java 15 Jan 2002 03:48:06 -0000 1.1
> +++ ValidatorServlet.java 15 Jan 2002 06:24:59 -0000 1.2
> @@ -84,10 +84,15 @@
>
> /**
> * The context-relative path to our configuration resource.
> - */
> + */
> protected String config = "WEB-INF/validation.xml";
>
> /**
> + * The context-relative path to our configuration resource of validator rules.
> + */
> + protected String configRules = "WEB-INF/validator-rules.xml";
> +
> + /**
> * The debugging detail level for this servlet.
> */
> protected int debug = 0;
> @@ -202,26 +207,54 @@
> * @exception ServletException if we cannot initialize these resources
> */
> protected void initMapping() throws IOException, ServletException {
> - // Acquire an input stream to our database file
> + resources = new ValidatorResources();
>
> // Initialize the context-relative path to our configuration resources
> String value = null;
> - value = getServletConfig().getInitParameter("config");
> - if (value != null)
> - config = value;
> - if (debug >= 1)
> - log("Loading validation file from '" + config + "'");
> + value = getServletConfig().getInitParameter("config-rules");
> + if (value != null) {
> + configRules = value;
> + }
> + if (debug >= 1) {
> + log("Loading validation rules file from '" + configRules + "'");
> + }
>
> InputStream input = null;
> + BufferedInputStream bis = null;
> + input = getServletContext().getResourceAsStream(configRules);
> + if (input != null) {
> + bis = new BufferedInputStream(input);
> +
> + try {
> + // pass in false so resources aren't processed
> + // until second file is loaded
> + ValidatorResourcesInitializer.initialize(resources, bis, false);
> + } catch (Exception e) {
> + log("ValidatorServlet::initMapping - " + e.getMessage(), debug);
> + }
> + } else {
> + log("Skipping validation rules file from '" + configRules + "'. No stream
>could be opened.");
> + }
> +
> +
> + value = getServletConfig().getInitParameter("config");
> + if (value != null) {
> + config = value;
> + }
> + if (debug >= 1) {
> + log("Loading validation file from '" + config + "'");
> + }
> +
> input = getServletContext().getResourceAsStream(config);
> - if (input == null)
> + if (input == null) {
> throw new UnavailableException("Can't load Validator XML file.");
> + }
>
> - BufferedInputStream bis = new BufferedInputStream(input);
> + bis = new BufferedInputStream(input);
>
> try {
> - resources = ValidatorResourcesInitializer.initialize(bis, debug);
> - // new HttpValidatorLog(getServletContext()), bis, debug);
> + // pass in true so resources are processed
> + ValidatorResourcesInitializer.initialize(resources, bis, true);
> } catch (Exception e) {
> log("ValidatorServlet::initMapping - " + e.getMessage(), debug);
> }
>
>
>
> 1.6 +0 -688
>jakarta-struts/contrib/validator/web/example/WEB-INF/validation.xml
>
> Index: validation.xml
> ===================================================================
> RCS file:
>/home/cvs/jakarta-struts/contrib/validator/web/example/WEB-INF/validation.xml,v
> retrieving revision 1.5
> retrieving revision 1.6
> diff -u -r1.5 -r1.6
> --- validation.xml 15 Jan 2002 03:57:40 -0000 1.5
> +++ validation.xml 15 Jan 2002 06:24:59 -0000 1.6
> @@ -2,694 +2,6 @@
> <global>
> <constant name="phone" value="^\(?(\d{3})\)?[-| ]?(\d{3})[-| ]?(\d{4})$" />
> <constant name="zip" value="^\d{5}\d*$" />
> -
> - <validator name="required"
> - classname="org.apache.struts.validator.util.StrutsValidator"
> - method="validateRequired"
> - 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.validator.util.StrutsValidator"
> - method="validateMinLength"
> - 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.validator.util.StrutsValidator"
> - method="validateMaxLength"
> - 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.validator.util.StrutsValidator"
> - method="validateMask"
> - 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.validator.util.StrutsValidator"
> - method="validateByte"
> - 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.validator.util.StrutsValidator"
> - method="validateShort"
> - 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.validator.util.StrutsValidator"
> - method="validateInteger"
> - 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.validator.util.StrutsValidator"
> - method="validateLong"
> - depends="required"
> - msg="errors.long"
> - />
> - <validator name="float"
> - classname="org.apache.struts.validator.util.StrutsValidator"
> - method="validateFloat"
> - 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.validator.util.StrutsValidator"
> - method="validateDouble"
> - depends="required"
> - msg="errors.double"/>
> -
> - <validator name="date"
> - classname="org.apache.struts.validator.util.StrutsValidator"
> - method="validateDate"
> - 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.validator.util.StrutsValidator"
> - method="validateRange"
> - 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.validator.util.StrutsValidator"
> - method="validateCreditCard"
> - 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.validator.util.StrutsValidator"
> - method="validateEmail"
> - 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 ([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>
> <formset>
> <constant name="zip" value="^\d{5}(-\d{4})?$" />
>
>
>
> 1.3 +4 -0 jakarta-struts/contrib/validator/web/example/WEB-INF/web.xml
>
> Index: web.xml
> ===================================================================
> RCS file: /home/cvs/jakarta-struts/contrib/validator/web/example/WEB-INF/web.xml,v
> retrieving revision 1.2
> retrieving revision 1.3
> diff -u -r1.2 -r1.3
> --- web.xml 15 Jan 2002 03:57:40 -0000 1.2
> +++ web.xml 15 Jan 2002 06:24:59 -0000 1.3
> @@ -10,6 +10,10 @@
> <servlet-name>validator</servlet-name>
>
><servlet-class>org.apache.struts.validator.action.ValidatorServlet</servlet-class>
> <init-param>
> + <param-name>config-rules</param-name>
> + <param-value>/WEB-INF/validator-rules.xml</param-value>
> + </init-param>
> + <init-param>
> <param-name>config</param-name>
> <param-value>/WEB-INF/validation.xml</param-value>
> </init-param>
>
>
>
>
> --
> To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>
>
>
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>