views:

32

answers:

3

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 \+ ?

+4  A: 

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.

Gumbo
+2  A: 

Escape it with a \?

meder
+3  A: 

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.

Marc B