Created
October 25, 2015 10:14
-
-
Save andrIvash/6f0ed720b6ef6b1b0075 to your computer and use it in GitHub Desktop.
validation form script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function validateThis(form) { | |
var | |
textType = form.find("[data-validation='text']"), | |
mailType = form.find("[data-validation='mail']"); | |
textType.each(function(){ | |
var | |
$this = $(this), | |
emptyField = $this.val() == ''; | |
if (emptyField) { | |
$this.tooltip({ | |
content : 'Заполните поле', | |
position : 'left' | |
}); | |
$this.addClass('error'); | |
} else { | |
$this.removeClass('error'); | |
} | |
}); | |
mailType.each(function(){ | |
var | |
$this = $(this), | |
regExp = /^([a-zA-Z0-9_.-])+@([a-zA-Z0-9_.-])+\.([a-zA-Z])+([a-zA-Z])+/, | |
isMail = regExp.test($this.val()); | |
if (isMail) { | |
$this.removeClass('error'); | |
} else { | |
$this.tooltip({ | |
content : 'Невалидный e-mail', | |
position : 'top' | |
}); | |
$this.addClass('error'); | |
} | |
}); | |
return form.find('.error').length == 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment