Q:

allow only alphabets and underscore using javascript

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;}

A:

The correct regex to use would be
/^[a-zA-Z\_]+$/g

^ matches beginning
$ matches end
g matches the whole string.