Help w/RegEx Needed

I need a RegEx pattern which tells me if the first character in a string is a 1 or not. This is going to be used on a telephone number like 15551234567. What I need to do is write a javascript function using RegEx to determine if the first character in the strong (telephone number) is a 1.

Tried all sorts of different snippets from the web, but nothing seems to be working and I am very new at this RegEx things.

Thanks
savetheorcasAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

McOzCommented:
Try this: it will return true or false.
function firstCharacterIsOne(str){
return str.match(/^1/);
}

Open in new window

0
point_pleasantCommented:
'^1\d{10}'
0
McOzCommented:
Oops, posted too soon. Change to this to return true or false:
function firstCharacterIsOne(str){
return str.match(/^1/)!=null;
}

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
point_pleasantCommented:
actually for a US phone number the regex should be (without dashes)
^1[2-9]\d{9}

with dashes

^1[2-9]\d{2}-\d{3}-\d{4}$


0
Albert Van HalenAnalyst developerCommented:
No need to use regular expressions (although you can, McOz solution is OK).
You can also use the simpler indexOf method. http://www.w3schools.com/jsref/jsref_IndexOf.asp
function firstCharacterIsOne(str) {
    return str.indexOf("1") == 0;
}

Open in new window

0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Regular Expressions

From novice to tech pro — start learning today.