How to add validation in Mobile Number input field?

How to validate the input field of Mobile Number?

For professional, it’s important to user don’t enter wrong values, for that we should have to validate all the fields like mobile number field, email id field.

Please check how can u easily validate the mobile number field..

<form action=“javascript:void(0);”>

<input id=“phonenumber” maxlength=“10” pattern=“^\d{4}\d{3}\d{3}$” required=“” oninvalid=“InvalidMsg(this);”  oninput=“InvalidMessage(this);”  type=“text” placeholder=“Mobile Number” />

<input type=“submit”>

</form>

<script language=“javascript”>
function InvalidMessage(textbox) {

if(textbox.validity.patternMismatch) {
textbox.setCustomValidity(‘please enter 10 Digit Mobile Number.’);
  } 
else {
textbox.setCustomValidity(”);
  }
    return true;
}
</script>


For Simple 10 Digit Validation :

<input maxlength=“10” type=“text”>

onTime It Solution

onTime IT Solution always happy to serve you in Information Technology (IT). Learn HTML, CSS, Javascript, PHP, Android, Digital Marketing, Latest IT News and many more.

Leave a Reply

Your email address will not be published. Required fields are marked *