...

View Full Version : Form Validation



holyearth
07-10-2007, 02:21 AM
The script below shows an error if the digit count is less than four or more than 5 ...



function validate2(form) {
if (form.pin.value.search( /^[0-9]{4}$/ ) == -1) {
alert('Please check your pin code and try again.');
form.pin.focus();
return false;
}
}


How can I change it so that it ONLY accepts 4, 5, or 6 digits long

rwedge
07-10-2007, 04:04 AM
To accept 4, 5, or 6 numbers try:
/^[0-9]{4,6}$/ or /^\d{4,6}$/

holyearth
07-10-2007, 05:40 AM
Thanks rwedge, that did it!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum