Case 1
If the validation is not for the last field of the form to be filled out, follow the steps given below.
- Set the onfocusout event for this button, as shown below.
- <div>Email Id: <input type="number" id="emailid" onfocusout="emailcheck();"></div>
- Create a function representing linked 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}$/;
- //var eml = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
- if (pattern.test(mobile)) {
- //alert("Your mobile number : " + mobile);
- return true;
- }
- alert("It is not a valid mobile number. Please input 10 digits only!");
- return false;
- }
Case 2
If the validation is the last field of the form to be filled (as displayed below), follow the steps given below to avoid multiple alert messages for the wrong Email entry.



Join the conversation! Your thoughts help the community grow.