Click to See Complete Forum and Search --> : Reg Expression validation


florida
12-22-2003, 02:25 PM
Please verify if I have this correct:



if(!/a-zA-Z0-9\//.test(document.pagename.fieldname.value))
{
alert("Invalid entry. Only letter, numbers and / are allowed.");
}



I want to send a message if something entered is not a letter(a through z capital and lowercasae) or a number or a "/").

ray326
12-22-2003, 03:57 PM
Does it not SEEM to be working? Try this instead.

(document.pagename.fieldname.value).match(/[a-zA-z0-9\/]+/)

florida
12-23-2003, 06:32 AM
Thanks

Jeff Mott
12-23-2003, 06:44 AM
Note, however, that all that will do is ensure that there is at least one valid character, not that all characters are valid.

Try this instead.if (/[^a-z\/]/i.test(document.pagename.fieldname.value))
alert("Invalid entry. Only letter, numbers and / are allowed.");

pyro
12-23-2003, 07:30 AM
Originally posted by Jeff Mott
Try this instead.Just forgot about the numbers, which bring us to:
if (/[^a-z0-9\/]/i.test(document.pagename.fieldname.value)) {
alert("Invalid entry. Only letter, numbers and / are allowed.");
}

Jeff Mott
12-23-2003, 08:06 AM
Just forgot about the numbershaha, my bad ;)

florida
12-23-2003, 08:58 AM
Thanks