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 \+
?
3 Answers
Reset to default 4You 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 \
?