How to validate the phone number ?

Any questions involving matching text strings to patterns - the pattern is called a "regular expression."

Moderator: General Moderators

Post Reply
premecorp
Forum Newbie
Posts: 15
Joined: Fri Nov 04, 2011 9:12 am

How to validate the phone number ?

Post by premecorp »

Hi,
I want to validate the phone number(landline or mobile) using a regular expression.
Phone number should be global (like used all over the world).
It may contain special characters(Optional) like "hypen"(-), or "Paranthesis"().
Ex: 086-104-2222
or (086)-104-2222
or 0861042222 (US)

or 9999999999 (Mobile)

or 08026693647 (India)

Can i get these done in a single expression
If anyone have any idea regarding this please help me...
mikeashfield
Forum Contributor
Posts: 159
Joined: Sat Oct 22, 2011 10:50 am

Re: How to validate the phone number ?

Post by mikeashfield »

RegEx should do the trick just nicely:

Code: Select all

^\(?([0-9]{3})\)?[-. ]?([0-9]{3})[-. ]?([0-9]{4})$
Post Reply