
Explain phone number validation using regular expression in JavaScript.

phone = phone.replace(/[^0-9]/g, '');
if(phone.length != 10) {
alert("not 10 digits");
} else {
alert("yep, its 10 digits");
}

function confirm1()
{
var PhoneNo=document.getElementById("<%=txtPhoneNo.ClientID %>");
var PhoneNoExp = /^[0-9]+$/;
if (!PhoneNo.value == "")
{
if (!PhoneNo.value.match(PhoneNoExp))
{
alert("Only numbers are allowed for Phone No \n");
PhoneNo.focus();
return false;
}
}
}