Friday 26 August 2011

Regular expression for phone number

this article show that how to validate phone number using regular expression.

Exp 1:

/^\d{3,4}-\d{7}$/;

In this expression "d" means only numeric values and "{3,4}" means 3 or 4 digits allowed at start of string before dash(-) and after dash(-) 7 digits required.

Exp 2:

/^\d{4}-\d{7}$/;

In this expression "d{4}" means 4 digits allowed at start of string before dash(-) and after dash(-) 7 digits required.

you can match these expressions with your input string like this.

function testContactNo(regExp,str)
{
     if ((str.search(regExp))) {
     alert('invalied number');
     }
}



No comments:

Post a Comment