I want to write a Javascript function so that the user is barred from entering invalid characters like"!@#$%^&*()_+" in a sensitive field like User Name.
Please Help.
Printable View
I want to write a Javascript function so that the user is barred from entering invalid characters like"!@#$%^&*()_+" in a sensitive field like User Name.
Please Help.
You can do this during validation of a form. Just see if any of them are in the string and if it is, cancel the submission of the form.
I haven't done much of javascript. Can i get the syntaxes pls.
Add an onClick event to the login button and call the functionCode://param val is string to check ie username
function isAlphaNumeric(val){
var str = new String(val);
return (str.search(/\W/)=="-1")?true:false;
}
if it's true and other validation ok then submit the form
Add it to the onsubmit of the form instead, it's the better place to put it (unless you have two submit buttons and you don't need the validation for one)