The form:
<section id="callback_header_js" class="form_holder clear form_holder_js"> <form id="header_form" action="/include_areas/ajax_sms_form.php" method="GET" enctype="multipart/form-data"> <input required="" class="itext input_mask_js" value="" name="BIG_NUMBER"> <button class="isubmit" type="submit">Перезвоните</button> </form> </section>
Script:
$(".input_mask_js").mask("+7(999)9999999"); $('#callback_header_js').on('submit', '#header_form', function(e) { if (!$(".input_mask_js").mask()) return false; var m_method=$(this).attr('method'); var m_data=$(this).serialize(); $.ajax({ type: m_method, url: '/include_areas/ajax_sms_form.php', data: m_data, success: function(result){ $('.form_holder_js').addClass('display_none'); $('.text_result_js').addClass('display_block'); } }); return false; });
The form sends the phone number, and if the number is not fully entered, the form is not sent, but for some reason the input becomes empty.
How not to reset the field when the value is entered incorrectly, but to display an alert with an error?