0

is any way to validate phone number in two forms? I would like to validate numbers beginning with "+" and phone without "+". For example, it should pass numbers +238472636 and 193785626.

Pattern: /^[\+]\d+$/

2 Answers 2

1

Use ? for optional characters or blocks:

Pattern: /^[\+]?\d+$/
Sign up to request clarification or add additional context in comments.

Comments

1

The ? quantifier matches the preceding element zero or one time. It is equivalent to {0,1}. ? is a greedy quantifier whose lazy equivalent is ??

so your reg. ex would be like this..

/^[\+]?\[0-9]+$/ OR
/^[\+]?\d+$/

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.