Web Development and Design | Tutorial for Java, PHP, HTML, Javascript: Validation

Web Development and Design | Tutorial for Java, PHP, HTML, Javascript: Validation
Showing posts with label Validation. Show all posts
Showing posts with label Validation. Show all posts

Jquery (js) validation For 10 Digit Mobile Numbers

Jquery (js) validation For 10 Digit Mobile Numbers




After Testing All Answer not getting success . Some times input take alpha character also.
Here is the last full working code With Only number input also keeping in mind backspace button key event for user if something number is incorrect.

html : 

<input name="phone" id="phone" placeholder="Mobile Number" class="form-control" type="number" required>

Js :

<script>
$("#phone").keydown(function(event) {
k=event.which;
if((k>=96 && k<=105) || k==8)
{
     if($(this).val().length==10)
     {
         if(k==8)
         {
             return true;
         }
         else
        {
             event.preventDefault();
             return false;

         }
    }
}
else
{
     event.preventDefault();
     return false;
}

});
</script>
7