Regular Expression allow alpha characters only?

A

Anonymous

Guest
Hi everyone, I've search google about regular expression that accept alpha characters only and there are alternatives
name starts with an upper case letter:
var re = /^[A-Z][A-Za-z]*$/
var re = /^[A-Z][A-Za-z]{2,}$/ /* to insist on upper case first letter */

I'm a beginner on javascript and I don't know how this code goes on. I know this one works with alpha but I need to know what is test. If I know what is test then I can try this code.Thanks.
Code:
var name1 = "Bob1";
var name2 = "Bob";

function isValidFirstName(fn)
{
    var re = /^[a-z]+$/i;
    return re.test(fn);
}

alert(isValidFirstName(name1));
alert(isValidFirstName(name2));
 
Hi!

.test is a Javascript method that checks or tests for a match in the string.

It will return true if it has match/es and false if none.

I hope this helps. Thank you.
 
I apologise, but, in my opinion, you are mistaken. Let's discuss it. Write to me in PM.
 
Back
Top