...

View Full Version : validate 6 numeric digits??



nikko50
04-21-2008, 05:30 PM
Hi guys!
If I have a field called "number" how can I validate that the user enters a 6 digit long number and also validate against a user typing "000000"?
Tracy

oesxyl
04-21-2008, 05:38 PM
Hi guys!
If I have a field called "number" how can I validate that the user enters a 6 digit long number and also validate against a user typing "000000"?
Tracy



result = /^[1-9]\d{5}/.test(numbervalue);

result is true for any number from 100000 to 999999.

regards

nikko50
04-21-2008, 05:42 PM
What if they are allowed to type in "011225". Number that start with 0.

oesxyl
04-21-2008, 05:48 PM
What if they are allowed to type in "011225". Number that start with 0.



val = parseInt(numval,10);
result = (val > 0 && val <= 999999) ? true : false);


from 1 to 999999.

regards

Philip M
04-21-2008, 06:11 PM
if (/^\d{6}$/.test(number.value) && (number.value > 0)) {

returns true for 000001 to 999999 (I understand that the user must enter exactly 6 digits with leading zeroes as necessary)

If the six digit number must be at least 100000 then:-

if (/^\d{6}$/.test(number.value) && (number.value >= 100000)) {

or as proposed by oesxyl

if (/^[1-9]\d{5}$/.test(number.value)) { // $ sign essential
returns true for 100000 - 999999



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum