Simple Javascript Form Field Validation
Quick Regex form validation to check if a field contains numbers only...
-
function isNumeric(elem, msg){
-
var alphaExp = /^<strong>[0-9]</strong>+$/;
-
if(elem.value.match(alphaExp)){
-
return true;
-
}else{
-
alert(msg);
-
elem.focus();
-
return false;
-
}
-
}
now letters only...
now alphaNumeric...
now alphaNumeric with underscores...
now with a highlight on the field in question...
usage (place the following in your opening form tag):
-
onsubmit="return isAlphaNumeric(document.getElementById('the_field_in_question'), 'your message!')"
... and make sure the input field itself has an ID of 'the_field_in_question'
Enjoy.
Meshach
You may Leave a comment or Subscribe to Comments RSS or Trackback this entry.
1 comment so far
Leave a comment
Please be polite and on topic. Your e-mail will never be published.
hi, I found your cloud search script on iloveyoutube.com and I'm trying to implement it on my web site, but without sucsess. I have different database, but I think that shouldn't be a problem but I always get an mysql_fetch_array(): supplied argument is not a valid MySQL result resource error... can you help?