You are missing a closing square bracket
^s*(?(020[7,8]{1})?[ ]?[1-9]{1}[0-9{2}[ ]?[0-9]{4})|(0[1-8]{1}[0-9]{3})?[ ]?[1-9]{1}[0-9]{2}[ ]?[0-9]{3})s*$
^
here
This should be working
^s*(?(020[7,8]{1})?[ ]?[1-9]{1}[0-9]{2}[ ]?[0-9]{4})|(0[1-8]{1}[0-9]{3})?[ ]?[1-9]{1}[0-9]{2}[ ]?[0-9]{3})s*$
Further you can remove some stuff from your expression.
{1}
is not need every character is still matched once
[ ]
is also not needed, just replace it with a space
[8,9]
is wrong. it will match 8, 9 and , . Use [89]
is correct.
Then it would look like that
^s*(?(020[78])? ?[1-9][0-9]{2} ?[0-9]{4})|(0[1-8][0-9]{3})? ?[1-9][0-9]{2} ?[0-9]{3})s*$
If you want to allow this not matched pattern 020 1234 5678 you could do for example
^s*(?(020[78]?)? ?[1-9][0-9]{2,3} ?[0-9]{4})$|^(0[1-8][0-9]{3})? ?[1-9][0-9]{2} ?[0-9]{3})s*$
^ ^^
made the [78] optional allows no 2 or 3 of `[0-9]`
See it here on Regexr
I have no clue if this is a valid UK phone number!
I fixed here also another bug in the regex a missing $
before and a missing ^
after the pipe |
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…