lawkunchi
lawkunchi

Reputation: 19

Validation of input mask

I'm using RobinHerbots/Inputmask plugin to mask tel input. I wanted to know how I can validate the input to make sure the user entered the correct information. Thank you!

 <form>
      <input type="tel" id="phone" name="phone">
 </form>

 <script>
    $("#phone").inputmask({"mask": "999-999-9999"});
 </script>

Upvotes: 0

Views: 7542

Answers (1)

mrdeadsven
mrdeadsven

Reputation: 774

The documentation state that you can use following code to notify your user if the correct format was inputted:

if ($(selector).inputmask("isComplete")){
    //do something
}

So for your case it could be something like:

if ($("#phone").inputmask("isComplete")){
    /* here you can do whatever you want to notify your user that it is correct 
       for example change the input color to green or something like that 
    */
    alert('your telephone input is correct');
}

Or if you follow the demo they used for you it would be something like:

$("#phone").inputmask({"mask": "999-999-9999"}, {
    oncomplete: function () {
       //Do something
    }
});

Upvotes: 3

Related Questions