tags:

views:

42

answers:

1

I have the following regex being used in javascript.

phone_number.match(/^1-\d{3}-\d{3}-\d{4}$/);

it works great with one exception. It allows spaces.

I want to strictly format 1-xxx-xxx-xxxx

but it allows 1- xxx-xxx-xxxx

anyone have any ideas how I can NOT allow spaces?

+2  A: 

No it does not. ;-) It is just impossible. In your regexp /^1-\d{3}-\d{3}-\d{4}$/ you do not have any space character - and it does not match (checked).

hsz