I am trying to validate the users name that is entered into a form box against the letters of the alphabet using a regular expression but cannot understand why it is coming back with an error when more than 1 'valid' letter is entered. I only want letters entered into the name box no special characters or numbers. The code is listed below.
var alphabet= /^[a-zA-Z]$/
function validate_firstname()
{
if(document.registration.firstname.value.search(alphabet)==-1)
{
errormsg+='invalid character entered.\n';
}
}
Is it the expresion thats wrong or is it my codeing. Any tips will be grateful.
var alphabet= /^[a-zA-Z]$/
function validate_firstname()
{
if(document.registration.firstname.value.search(alphabet)==-1)
{
errormsg+='invalid character entered.\n';
}
}
Is it the expresion thats wrong or is it my codeing. Any tips will be grateful.