commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "David Graham" <dgraham1...@hotmail.com>
Subject Re: Problem with validator-rules.xml
Date Mon, 10 Mar 2003 16:00:11 GMT
Please open a bugzilla report for this.

Thanks!
David



>From: "Flentje, Chad" <Chad.Flentje@firepond.com>
>Reply-To: "Jakarta Commons Developers List" 
><commons-dev@jakarta.apache.org>
>To: "'commons-dev@jakarta.apache.org'" <commons-dev@jakarta.apache.org>
>Subject: Problem with validator-rules.xml
>Date: Mon, 10 Mar 2003 09:53:30 -0600
>
>Greetings.
>
>I'm not sure if this is the correct e-mail address to post bugs with the
>validator, but I'll give it a try anyway.
>If this isn't the correct place to post bugs, can you tell my the proper
>place and/or procedure? Thanks.
>
>Problem exists in the validator-rules.xml for the validator named integer.
>Specifically regarding the javascript used for client-side validation.
>
>Bug #1
>Description
>The javascript code to validate integers does not validate negative numbers
>correctly. Negative integers are being validated as invalid. They should be
>valid.
>
>Solution to correct the problem
>1. Add a check to the isAllDigits function to look for the minus (-)
>character.
>2. Change the initialization value in the for loop to use the startFrom
>variable.
>
>		Example
>             function isAllDigits(argvalue) {
>                 argvalue = argvalue.toString();
>                 var validChars = "0123456789";
>                 var startFrom = 0;
>                 if (argvalue.substring(0, 2) == "0x") {
>                    validChars = "0123456789abcdefABCDEF";
>                    startFrom = 2;
>                 } else if (argvalue.charAt(0) == "0") {
>                    validChars = "01234567";
>                    startFrom = 1;
>                 } else if (argvalue.charAt(0) == "-") {
>                    startFrom = 1;
>                 }
>                 for (var n = startFrom; n < argvalue.length; n++) {
>                     if (validChars.indexOf(argvalue.substring(n, n+1)) ==
>-1) return false;
>                 }
>                 return true;
>
>
>Bug #2
>Description
>The javascript code to validate integers does not display an alert box if
>the number being validated has invalid digits. (i.e. floating point 
>numbers)
>
>Solution to correct the problem
>1. If the call to function isAllDigits fails, then variables focusField and
>fields should be set properly so an alert message can be presented to the
>user.
>
>		Example
>             function validateInteger(form) {
>                 var bValid = true;
>                 var focusField = null;
>                 var i = 0;
>                 var fields = new Array();
>                 oInteger = new IntegerValidations();
>                 for (x in oInteger) {
>                 	var field = form[oInteger[x][0]];
>
>                     if (field.type == 'text' ||
>                         field.type == 'textarea' ||
>                         field.type == 'select-one' ||
>                         field.type == 'radio') {
>
>                         var value = '';
>						// get field's value
>						if (field.type ==
>"select-one") {
>							var si =
>field.selectedIndex;
>						    if (si >= 0) {
>							    value =
>field.options[si].value;
>						    }
>						} else {
>							value = field.value;
>						}
>
>                         if (value.length > 0) {
>
>                             if (!isAllDigits(value)) {
>                                 if (i == 0) {
>                                     focusField = field;
>                                 }
>                                 fields[i++] = oInteger[x][1];
>                                 bValid = false;
>                             } else {
>	                            var iValue = parseInt(value);
>	                            if (isNaN(iValue) || !(iValue >=
>-2147483648 && iValue <= 2147483647)) {
>	                                if (i == 0) {
>	                                    focusField = field;
>	                                }
>	                                fields[i++] = oInteger[x][1];
>	                                bValid = false;
>	                           }
>                            }
>                        }
>                     }
>                 }
>                 if (fields.length > 0) {
>                    focusField.focus();
>                    alert(fields.join('\n'));
>                 }
>                 return bValid;
>             }
>
>Thanks,
>Chad
>
>
>Chad K. Flentje
>Firepond - Senior Consultant
>Bloomington, MN  USA
>e-mail:	   chad.flentje@firepond.com
>messenger:  chad_flentje@hotmail.com
>office:	   952.229.2340
>mobile:	   612.207.5200
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: commons-dev-help@jakarta.apache.org


_________________________________________________________________
MSN 8 with e-mail virus protection service: 2 months FREE*  
http://join.msn.com/?page=features/virus


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


Mime
View raw message