Communities for your favorite technologies. Explore all Collectives
Ask questions, find answers and collaborate at work with Stack Overflow for Teams.
Ask questions, find answers and collaborate at work with Stack Overflow for Teams. Explore Teams
Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
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+$/
Use ? for optional characters or blocks:
Pattern: /^[\+]?\d+$/
Add a comment
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+$/
Start asking to get answers
Find the answer to your question by asking.
Explore related questions
See similar questions with these tags.