Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Invalid regular expression:Lone quantifier brackets

Tags:

regex

I have a html phone pattern that will accept these formats :

+61 x xxxx xxxx,
+61xxxxxxxxx,
0x xxxx xxxx,
0xxxxxxxxx,
xxxx xxxx,
xxxxxxxx,
+xx xxx xxx xxx,
+xxxxxxxxxxx,
0xxx xxx xxx,
0xxxxxxxxx

It was working few months ago, now suddenly my phone fields are not validating . I'm having this error:

Pattern attribute value ^(?:0|\(?\+61\)?\s?|0061\s?)[1-79](?:[\.\-\s]?\d\d){4}|(\d{4}[\s]\d{4})|(\d{8})|(\d{4}[\s]\d{3}[\s]\d{3})|(\+61\[\s]\d{3}[\s]\d{3}[\s]\d{3})|(\+61\s\d{3}\s\d{3}\s\d{3})$ is not a valid regular expression: Uncaught SyntaxError: Invalid regular expression: /^(?:0|\(?\+61\)?\s?|0061\s?)[1-79](?:[\.\-\s]?\d\d){4}|(\d{4}[\s]\d{4})|(\d{8})|(\d{4}[\s]\d{3}[\s]\d{3})|(\+61\[\s]\d{3}[\s]\d{3}[\s]\d{3})|(\+61\s\d{3}\s\d{3}\s\d{3})$/: Lone quantifier brackets 
like image 762
Edsel Abucejo Avatar asked May 07 '26 14:05

Edsel Abucejo


1 Answers

So far, no one cared to show where in your pattern the error is.

…|(\+61\[\s]\d{3}[\s]\d{3}[\s]\d{3})|(\+61\s\d{3}\s\d{3}\s\d{3})$
       ^

There by mistake you inserted a backslash, escaping the opening bracket, so making it an ordinary character and leaving the closing bracket Lone. (Sadly the error message is somewhat misleading, since those brackets are of course not quantifier brackets.)

like image 85
Armali Avatar answered May 09 '26 02:05

Armali