
JavaScript regex validate Mobile no.

<html>
<head>
<title>Mobile number validation using regex</title>
<script type="text/javascript">
function validate() {
var mobile = document.getElementById("mobile").value;
var pattern = /^\d{10}$/;
if (pattern.test(mobile)) {
alert("Your mobile number : "+mobile);
return true;
}
alert("It is not valid mobile number.input 10 digits number!");
return false;
}
</script>
</head>
<body>
<h2>Validating mobile number..</h2>
Enter Mobile No. :
<input type="text" name="mobile" id="mobile" />
<input type="submit" value="Check" onclick="validate();" />
</body>
</html>

The above example validate 10 digit (eg-9675647324) mobile number
by using regular expression- /^\d{10}$/;
Here /../(forward slashes) is used to quote your regular expression.
^ shows beginning of string.
\d{10} shows any digit 0-9 having 10 places.
$ is used for ending the string.
Test() method takes one argument and check that to the pattern.
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.