开发者

Invalid quantifer error using Regular Expression (UK Telephone numbers)

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜