Вот как проходит валидация форм:
// Request Demo Form
{
// Variables
{
/* Inputs
var $demo = $('#request-demo'),
$popup = $('#request-popup'),
requestForm = $demo.length ? $demo : $popup;
*/
var requestForm = $('#request-demo'),
fullNameInput = $('#fullName'),
fullNameError = false,
phoneNumberInput = $('#phoneNumber'),
phoneNumberError = false,
emailInput = $('#email'),
emailError = false,
messageInput = $('#message'),
messageError = false,
numberCheck = /^\+?[0-9]+$/,
specialCharactersCheck = /^[а-яА-ЯёЁa-zA-Z0-9- ]*$/,
emailCheck = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
}
// Inputs Validations
{
var fullNameValidate = function(){
var fullNameVal = fullNameInput.val();
if(!fullNameVal.trim() || fullNameVal == null || fullNameVal == "" || !fullNameVal.match(specialCharactersCheck)){
fullNameInput.addClass('invalid').removeClass('valid');
fullNameError = true;
// $('html, body').animate({scrollTop: fullNameInput.offset().top - 100}, 1000);
}else{
fullNameInput.removeClass('invalid').addClass('valid');
fullNameError = false;
}
return fullNameError;
}
fullNameInput.on('keyup focusout blur', function(e){
fullNameValidate();
});
var phoneNumberValidate = function(){
var phoneNumberVal = phoneNumberInput.val();
if(phoneNumberVal == null || phoneNumberVal == "" || !phoneNumberVal.match(numberCheck)){
phoneNumberInput.addClass('invalid').removeClass('valid');
phoneNumberError = true;
// $('html, body').animate({scrollTop: phoneNumberInput.offset().top - 100}, 1000);
}else{
phoneNumberInput.removeClass('invalid').addClass('valid');
phoneNumberError = false;
}
return phoneNumberError;
}
phoneNumberInput.on('keyup focusout blur', function(e){
phoneNumberValidate();
});
var emailValidate = function(){
var emailVal = emailInput.val();
if(!emailVal.trim() || emailVal == null || emailVal == "" || !emailVal.match(emailCheck)){
emailInput.addClass('invalid').removeClass('valid');
emailError = true;
// $('html, body').animate({scrollTop: emailInput.offset().top - 100}, 1000);
}else{
emailInput.removeClass('invalid').addClass('valid');
emailError = false;
}
return emailError;
}
emailInput.on('keyup focusout blur', function(e){
emailValidate();
});
var messageValidate = function(){
var messageVal = messageInput.val();
if(!messageVal.trim() || messageVal == null || messageVal == ""){
messageInput.removeClass('invalid').removeClass('valid');
}else{
messageInput.addClass('valid').removeClass('invalid');
}
}
messageInput.on('keyup focusout blur', function(e){
messageValidate();
});
$('.close-requested').on('click', function(){
requestForm.removeClass('requested');
})
}