user3286794 user3286794 - 1 year ago 190
PHP Question

validation for 10 digit mobile number in jquery

I need the code for validating email and mobile number in jQuery and also

on that particular field where validations are not satisfied.

This is my query

<form name="enquiry_form" method="post" id="enquiry_form">

Full Name *
<input class="input-style" name="name" id="name" type="text" required>
Email *
<input class="input-style" name="email" id="email" type="email" required>
Phone *
<input name="mobile" id="mobile" type="number" required>

<input type="submit" value="SUBMIT" id="enq_submit"">


Answer Source

for email validation, <input type="email"> is enough..

for mobile no use pattern attribute for input as follows:

<input type="number" pattern="\d{3}[\-]\d{3}[\-]\d{4}" required>

you can check for more patterns on

for focusing on field, you can use onkeyup() event as:

function check()

    var pass1 = document.getElementById('mobile');

    var message = document.getElementById('message');

   var goodColor = "#0C6";
    var badColor = "#FF9B37";

    if(mobile.value.length!=10){ = badColor; = badColor;
        message.innerHTML = "required 10 digits, match requested format!"

and your HTML code should be:

<input name="mobile"  id="mobile" type="number" required onkeyup="check(); return false;" ><span id="message"></span>
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download