Regular Expression allow alpha characters only?

Javascript coding ..

Moderators: egami, macek, gesf

Post Reply
New php-forum User
New php-forum User
Posts: 18
Joined: Mon Jan 23, 2012 7:40 pm

Sat Jan 28, 2012 11:56 pm

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: Select all

var name1 = "Bob1";
var name2 = "Bob";

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

User avatar
php-forum Fan User
php-forum Fan User
Posts: 65
Joined: Mon Jun 13, 2011 9:25 pm
Location: Pasig City, Philippines

Tue Aug 05, 2014 12:02 am


.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.
User avatar
New php-forum User
New php-forum User
Posts: 5
Joined: Fri Jun 05, 2015 2:26 am
Location: US

Wed Jun 17, 2015 11:56 pm

I apologise, but, in my opinion, you are mistaken. Let's discuss it. Write to me in PM.
Post Reply