Reputation: 289
I am working on a form validation and I need to validate phone number with or without country code. Example: +1-555-532-3455, 555-555-5555, +919965425422.
Can any one suggest me how to achieve it with regular expression.
Upvotes: 1
Views: 8674
Reputation: 1308
try like this
<script type="text/javascript">
var reg = "(?:\s+|)((0|(?:(\+|)91))(?:\s|-)*(?:(?:\d(?:\s|-)*\d{9})|(?:\d{2}(?:\s|-)*\d{8})|(?:\d{3}(?:\s|-)*\d{7}))|\d{10})(?:\s+|)";
function PhoneValidation(phoneNumber)
{
var OK = reg.match(phoneNumber);
if (!OK) {
window.alert("phone number isn't valid");
}else{
window.alert("phone number is valid");
}
}
</script>
Upvotes: 6