Hi there,
I want to validate UK phone numbers which are always 11 chars starting with a zero. That part is simple however, I would like to permit the user to also enter whitespace and/or hyphens. Opinion differs on where those characters should go so I'm happy to allow the user to do whatever they feel like and simply strip those chars out later. All the following should pass...
07816924120
078 1692 4120, 078-1692-4120
0781 692 4120, 0781-692-4120
07816 924 120, 07816-924-120
07816 924120, 07816-924120 even...
0 7 8 1 6 9 2 4 1 2 0 or...
078-1692 4120
Essentially as long as there's 11 digits (no more, no less), no consecutive whitespaces or hyphens, the first digit is a zero and the second digit is a non-zero digit it should match, everything else should fail. Happily I can ignore country codes and suchlike.
I'm would like the same regex to work in both python and javascript.
The regex I have does work but it's very ugly/ repetitive...
^[ -]{0,1}0[ -]{0,1}[1-9][ -]{0,1}[0-9][ -]{0,1}[0-9][ -]{0,1}[0-9][ -]{0,1}[0-9][ -]{0,1}[0-9][ -]{0,1}[0-9][ -]{0,1}[0-9][ -]{0,1}[0-9][ -]{0,1}[0-9]$
Told you!
I'm assuming there's got to be a neater / more concise way of writing this, is that a fair assumption? and if so what's the trick?
Cheers,
Roger Heathcote