- Created a form with the field name, phone, email, city, message. Fields name, email, city - required (required). The message field and telephone are optional.
- Phone field
<input type="tel" class="inputbox" id="clientPhone" name="telephone"/>
- jquery.min.js library has been added to display the phone mask
$("#clientPhone").mask("+38(999)999-99-99");
4.Question: if the telephone field is not filled in the form is not sent, how to write a check to send the form when the telephone field is not filled (so as not to take into account the phone mask) in order to make it possible to send the form without the telephone entered?
$(document).ready(function() { $('#btn-send').click(function(event) { event.preventDefault(); var telephone = $('#clientPhone').val(); if (telephone == "") { $('#clientPhone').addClass('Valid'); return true; } //Проверка поля Имя else { var name = $('#clientName').val(); if (name.length < 2) { $('#clientName').addClass('notValid'); $(this).next().text('Введите, пожалуйста, Ваше имя, не менее двух символов').fadeOut(10000); return false; } //Проверка поля Город else { var city = $('#clientCity').val(); if (city.length < 2) { $('#clientCity').addClass('notValid'); $(this).next().text('Введите, пожалуйста, название Города, не менее двух символов'); return false; } //Проверка поля email else { var email = $('#clientEmail').val(); var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,6})+$/; if (filter.test(email) == false) { $('#clientEmail').addClass('notValid'); $(this).next().text('Заполните, пожалуйста, поле e-mail. Пример формата поля e-mail: test@test.test'); return false; } //отправка формы если все ок else { $('#userFeedback').submit(); // отправляем форму msg = 'Спасибо, Ваша заявка принята. С Вами свяжутся в ближайшее время'; result = msg; $("#userFeedback").html(result); } } } } }); });
if
block. - Igorjquery.min.js
orjquery.maskedinput.min.js
? digitalbush.com/projects/masked-input-plugin - Gleb Kemarsky