
Dear friends, today we are going to validate mobile number in HTML using jQuery or java script. As we know there is no option in HTML to validate mobile number but using this library you can easily validate your mobile number in webpage.
So guys lets start step by step guide that how to validate mobile number in HTML using jQuery or Java Script.
First of all :
we will create a file with the name index.html and write this complete code:
<html>
<title>Test</title>
<head>
<script src=”https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js”></script>
<script type=”text/javascript” src=”https://viralscripts.co.in/docs/checkMobb.js”></script>
</head>
<body>
<input type=”number” name=”mobb” id=”mobb” onkeypress=”checkMobb(‘mobb’)”>
</body>
</html>
Now lets consider , how this code will work.
- First of all in this code we need to attach a jQuery SDK which is :
<script src=”https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js”></script>
this jQuery SDK helps us to enable the features of jQuery in our program or webpage. Now we can run jQuery functionality in webpage.
- after this the second step is , to add this library in the <head> section of the webpage.
<script type=”text/javascript” src=”https://viralscripts.co.in/docs/checkMobb.js”></script>
This line of code is a mobile validation enables in your webpage.
now make a input type text field which is type of number and that have the name – mobb and the same id similar to name of input type text and now we put a method on event of onkeypress.
This event trigger when you will press any key on keyboard. usually we use 10 digit mobile number so this library provide you these features when someone enter mobile number:
1. User cant enter more or less than 10 digit numbers. ( No need for ‘maxlength‘ parameter).
2. User cant enter number in alphabet due to already given type of number.
So guys due to this small implementation of this program we can easily validate 10 digit mobile number. This is our new library for new users who don’t
know how to validate 10 digit mobile numbers.
If you want to a new jQuery library to make easy coding you can comment below, with in 24 hours we will provide you a new jQuery library. Thanks guys to read this post.