Skip to content

Instantly share code, notes, and snippets.

@andrIvash
Created October 25, 2015 10:14
Show Gist options
  • Save andrIvash/6f0ed720b6ef6b1b0075 to your computer and use it in GitHub Desktop.
Save andrIvash/6f0ed720b6ef6b1b0075 to your computer and use it in GitHub Desktop.
validation form script
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