Hi Buddies,
How can i restrict users fro entering special characters in the text box.I want only numbers and alphabets to be entered ( Typed / Pasted ) Any Samples ?
Thanks in advance
Hi Buddies,
How can i restrict users fro entering special characters in the text box.I want only numbers and alphabets to be entered ( Typed / Pasted ) Any Samples ?
Thanks in advance
Basically, just use an appropriate onkeypress handler. See http://www.qodo.co.uk/blog/javascript-restrict-keyboard-character-input/ and the example http://www.qodo.co.uk/wp-content/uploads/2008/05/javascript-restrict-keyboard-character-input.html
It would help you... assume you have a form with "formname" form and a text box with "txt" name. then you can use following code to allow only aphanumeric values
var checkString = document.formname.txt.value;
if (checkString != "") {
if ( /[^A-Za-z\d]/.test(checkString)) {
alert("Please enter only letter and numeric characters");
document.formname.txt.focus();
return (false);
}
}
You have two approaches to this:
I would suggest the second method coz its less irritating.
Additionally, I will also suggest that you reconsider if you really want to prevent users from entering special characters. Because many people have $, #, @ and * in thier passwords.
I presume that this might be in order to prevent SQL injection; if so: its better that you handle the checks server-side. Or better still, escape the values and store them in the database.
cheers, jrh.
i need to see the method of special character validation in javascript