-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
56 lines (56 loc) · 1.91 KB
/
main.js
File metadata and controls
56 lines (56 loc) · 1.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
(function($) {
"use strict";
$('.validate-input .input100').each(function() {
$(this).on('blur', function() {
if (validate(this) == false) {
showValidate(this);
} else {
$(this).parent().addClass('true-validate');
}
})
})
var input = $('.validate-input .input100');
$('.validate-form').on('submit', function() {
var check = true;
for (var i = 0; i < input.length; i++) {
if (validate(input[i]) == false) {
showValidate(input[i]);
check = false;
}
}
return check;
});
$('.validate-form .input100').each(function() {
$(this).focus(function() {
hideValidate(this);
$(this).parent().removeClass('true-validate');
});
});
function validate(input) {
if ($(input).attr('type') == 'email' || $(input).attr('name') == 'email') {
if ($(input).val().trim().match(/^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{1,5}|[0-9]{1,3})(\]?)$/) == null) {
return false;
}
} else {
if ($(input).val().trim() == '') {
return false;
}
}
}
function showValidate(input) {
var thisAlert = $(input).parent();
$(thisAlert).addClass('alert-validate');
$(thisAlert).append('<span class="btn-hide-validate"></span>')
$('.btn-hide-validate').each(function() {
$(this).on('click', function() {
hideValidate(this);
});
});
}
function hideValidate(input) {
var thisAlert = $(input).parent();
$(thisAlert).removeClass('alert-validate');
$(thisAlert).find('.btn-hide-validate').remove();
}
}
)(jQuery);