最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Regular expression using + problem in js - Stack Overflow

programmeradmin2浏览0评论

I am using regular expression. In phone validation, i have to use the "+" sign in that. How to provide the + sign in regular expression. Because + sign indicates one or more of preceding character(s). Whether i will provide like this \+ ?

I am using regular expression. In phone validation, i have to use the "+" sign in that. How to provide the + sign in regular expression. Because + sign indicates one or more of preceding character(s). Whether i will provide like this \+ ?

Share Improve this question edited Jun 15, 2010 at 9:40 Karthik asked Jun 14, 2010 at 5:44 KarthikKarthik 3,3115 gold badges30 silver badges38 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 4

You need to escape it with a preceding \ like:

/^\+\d+$/

This example does only match strings that start with a + that is followed by one or more digits.

As a pretty much universal rule with regex engines, you can escape metacharacters with a backslash, so that while + by itself indicates "1 or more", \+ is just a plus sign.

Escape it with a \?

发布评论

评论列表(0)

  1. 暂无评论