Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Newbie Validation problem

Status
Not open for further replies.

Jastper

Programmer
Oct 4, 2002
13
0
0
GB
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.
 
try adding the + and global/ignore case to the regex
as
var alphabet= /^[a-zA-Z]+$/gi

_________________________________________________________
for the best results to your questions: FAQ333-2924
[sub]01001111 01101110 01110000 01101110 01110100[/sub]
onpnt2.gif
[sup] [/sub]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top