There is a condition:

if (!phone || phone.replace(/\D/g, '').length < 12) enable = false; if (codes[phone.substr(5, 3)]) valid = true; 

Markup:

  <form> <div class="column"> <div class="form-group"> <input type="text" class="form-control" placeholder="Ваш телефон" name="phone" data-mask="+38 (099) 999-99-99" required/> </div> </div> <div class="column"> <div class="form-controls"> <button type="button" class="btn btn-red btn-large btn-block btn-submit" required disabled="disabled">Заказать звонок</button> </div> </div> </form> 

How can I display the message “incorrect input” in the input, in case of non-observance of these conditions?

Here is the full code: jsfiddle.net/0xL0fctq/31

    1 answer 1

     if (!phone || phone.replace(/\D/g, '').length < 12) enable = false; if (codes[phone.substr(5, 3)]) { valid = true } else if (enable==true) { $('.form-control').val('Некорректный ввод'); } 

    Here is the code. I correctly understood the essence of the question? But why bring in the input itself? You can display an error message next.

    • @ Plikard, and how to display a message ??? - Valeriy1996
    • one
      Create a block with the class .hidden {display: none} containing the error text and remove the class with $('#error').removeClass('hidden'); when you need to show an error - Plikard