Set the onfocusout event for this button as shown below.
- <div>Mobile No: <input type="number" id="phonenumber" onfocusout="mobilecheck();"></div>
Create a function representing a link to that button and it gets executed when triggered.
- function mobilecheck() {
- var mobile = document.getElementById("phonenumber").value;
- var pattern = /^[1-9]{1}[0-9]{9}$/;
-
- if (pattern.test(mobile)) {
-
- return true;
- }
- alert("It is not a valid mobile number. Please input 10 digits only!");
- return false;
- }
Go to the site page and start filling in the details.
Here the validation message for Mobile number pops up, if entered wrong.