开发者

Invalid quantifer error using Regular Expression (UK Telephone numbers)

开发者 https://www.devze.com 2023-02-03 23:39 出处:网络
I am getting the error \"Invalid Quantifier\" when using thi开发者_Go百科s regex: ^(((\\+44\\s?\\d{4}|\\(?0\\d{4}\\)?)\\s?\\d{3}\\s?\\d{3})|((\\+44\\s?\\d{3}|\\(?0\\d{3}\\)?)\\s?\\d{3}\\s?\\d{4})|((\

I am getting the error "Invalid Quantifier" when using thi开发者_Go百科s regex:

^(((\+44\s?\d{4}|\(?0\d{4}\)?)\s?\d{3}\s?\d{3})|((\+44\s?\d{3}|\(?0\d{3}\)?)\s?\d{3}\s?\d{4})|((\+44\s?\d{2}|\(?0\d{2}\)?)\s?\d{4}\s?\d{4}))(\s?\#(\d{4}|\d{3}))?$

Infact ive tried a few UK telephone number regex's from the regex librairy but im getting the same error all the time. If anyone can help id be much appreciative!


You get the same error if you simply run this:

new RegExp("^(((+44\s?\d{4}|(?0\d{4})?)\s?\d{3}\s?\d{3})|((+44\s?\d{3}|(?0\d{3})?)\s?\d{3}\s?\d{4})|((+44\s?\d{2}|(?0\d{2})?)\s?\d{4}\s?\d{4}))(\s?#(\d{4}|\d{3}))?$");

... so you'd better forget about jQuery and Form Validator until you get the regexp right.

The JavaScript console says this:

Error: invalid quantifier +44s?d{4}|(?0d{4})?)s?d{3}s?d{3})|((+44s?d{3}|(?0d{3})?)s?d{3}s?d{4})|((+44s?d{2}|(?0d{2})?)s?d{4}s?d{4}))(s?#(d{4}|d{3}))?$

The + quantifier means one or more is used to modify a previous rule, e.g.:

A+ --> One or more A's
\d+ --> One or more digits

So you need something to quantify:

(((+ --> Nothing to modify


Use this, its from http://www.regexlib.com/Search.aspx?k=uk%20tele

(\s*\(?0\d{4}\)?(\s*|-)\d{3}(\s*|-)\d{3}\s*)|(\s*\(?0\d{3}\)?(\s*|-)\d{3}(\s*|-)\d{4}\s*)|(\s*(7|8)(\d{7}|\d{3}(\-|\s{1})\d{4})\s*)
0

精彩评论

暂无评论...
验证码 换一张
取 消