hi there i have a form field which i need to validate. this feild can accept numbers as well as this format e.g 1-2 and 1,2,3,4,5
how do i go about it?![]()
| SitePoint Sponsor |
hi there i have a form field which i need to validate. this feild can accept numbers as well as this format e.g 1-2 and 1,2,3,4,5
how do i go about it?![]()





You'd want something like this:
HTML Code:<script type="text/javascript"> function checkIt(elm) { if (elm.value.test(/^[0-9]+-[0-9]+$|^[0-9]+(,[0-9])*$/)) { return true; } alert('Your field is wrong!!!?!?!'); return false; } </script> <form onsubmit="return checkIt(yourField)" action=""> <input name="yourField" type="text" value="blah" /> </form>
ck :: bringing chris to the masses.
i havea validate function and i adde this bit of code but it doest seem to work?
how do i solve this?PHP Code:function DataValidation()
{
if (document.addform.block.value == "") {
alert("You must enter a value for Block!");
return false;
else
if (document.addform.block.value(/^[0-9]+-[0-9]+$|^[0-9]+(,[0-9])*$/)) {
return true;
} alert('Your field is wrong!');
return false;
elm.focus();
elm.select();
}
}
:
:
:
:





You forgot .test after .value
ck :: bringing chris to the masses.
Bookmarks