Regular Expression allow alpha characters only?

Javascript coding ..

Moderators: macek, egami, gesf

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

Regular Expression allow alpha characters only?

Postby bobbygerez » 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);
}

alert(isValidFirstName(name1));
alert(isValidFirstName(name2));

User avatar
WebOutGateway
New php-forum User
New php-forum User
Posts: 37
Joined: Mon Jun 13, 2011 9:25 pm
Location: Pasig City, Philippines
Contact:

Re: Regular Expression allow alpha characters only?

Postby WebOutGateway » Tue Aug 05, 2014 12:02 am

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.


Return to “JavaScript”

Who is online

Users browsing this forum: No registered users and 1 guest

cron