I need to validate phone number in PHP. I have made following regex, but I also need to it to accept numbers starting with plus char, how can I do that?
^[0-9]$
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The regex you provided in your question (
^[0-9]$) will only match a one digit phone number.At the very least you probably need to add the
+modifier to allow one or more digits:To add an optional
+at the beginning, you’ll need to escape it since+is a special character in regular expressions:And finally,
\dis shorthand for[0-9]so you could shorten the expression to