allow only alphabets and underscore using javascript
Posted
by Priyanka
on Stack Overflow
See other posts from Stack Overflow
or by Priyanka
Published on 2010-04-16T09:52:53Z
Indexed on
2010/04/16
10:03 UTC
Read the original article
Hit count: 374
JavaScript
Hello.I am allowing a string to contain only alphabets and underscore,but is i enter fist character as alphabet or underscore and later if i put any invalid character then this validation is being done.I have done validation as follows:
function permission_validate()
{var permission=document.permissionForm.permission.value;var allowedStr=/[A-Za-z_]/;
if(!allowedStr.test(permission)){document.getElementById("permission_Er").innerHTML="* Required field can contain Only A-Z/az/_";
document.permissionForm.permission.focus();return false;}else{return true;}
© Stack Overflow or respective owner