Link to home
Start Free TrialLog in
Avatar of savetheorcas
savetheorcas

asked on

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
Avatar of McOz
McOz

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

Open in new window

'^1\d{10}'
ASKER CERTIFIED SOLUTION
Avatar of McOz
McOz

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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}$


SOLUTION
Avatar of Albert Van Halen
Albert Van Halen
Flag of Netherlands image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial