1

Could anyone please give a regular expression for jQuery validation on a home phone number which will force the following criteria:

  • 11 Digits exactly
  • Must begin with 0
  • Must NOT begin with 07

I currently have a regex which forces 11 digits beginning with 07:

/^07\d{9}$/

This works fine for a mobile number but just need a slightly modified version for a land line.

User787665
  • 237
  • 4
  • 23
  • 2
    This has been covered dozens of times on SO - [http://stackoverflow.com/questions/4395058/regular-expression-for-matching-a-phone-number][1] [1]: http://stackoverflow.com/questions/4395058/regular-expression-for-matching-a-phone-number – Aaron Dec 24 '11 at 13:09
  • 1
    Why do you want to reject _my_ home phone number? – nnnnnn Dec 24 '11 at 13:58
  • What you are doing is almost certainly wrong. Don't do it. – Tom Anderson Dec 24 '11 at 14:42
  • @BryceAtNetwork23 Sorry I am new and should have searched past questions before posting. I am sending leads to a company and this is their specification. Sending phone numbers which do not match this criteria will result in an error. – User787665 Dec 24 '11 at 14:54

3 Answers3

6

You can either do simple

/^0[0-689]\d{9}$/

or a look-ahead like

/^0(?!7)\d{10}$/

Please bear in mind to make it not to restricitive, for example allow spaces (and just remove them before validation) to make the input more user-friendly.

Bergi
  • 630,263
  • 148
  • 957
  • 1,375
3

This will work:

/^0[012345689]\d{9}$/

I made a test harness for it as well.

FishBasketGordo
  • 22,904
  • 4
  • 58
  • 91
  • 1
    +1, although I'm guessing `0` is also not allowed as the second number as this would result in an international call. – Tim Pietzcker Dec 24 '11 at 13:13
1

I think this regular expression would match what you want.

/^0[0123456890]\d{9}$/
RageZ
  • 26,800
  • 12
  • 67
  • 76