-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathform-validation.js
58 lines (55 loc) · 1.81 KB
/
form-validation.js
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
57
58
$(function () {
$('#form_validation').validate({
rules: {
'checkbox': {
required: true
},
'gender': {
required: true
}
},
highlight: function (input) {
$(input).parents('.form-line').addClass('error');
},
unhighlight: function (input) {
$(input).parents('.form-line').removeClass('error');
},
errorPlacement: function (error, element) {
$(element).parents('.form-group').append(error);
}
});
//Advanced Form Validation
$('#form_advanced_validation').validate({
rules: {
'date': {
customdate: true
},
'creditcard': {
creditcard: true
}
},
highlight: function (input) {
$(input).parents('.form-line').addClass('error');
},
unhighlight: function (input) {
$(input).parents('.form-line').removeClass('error');
},
errorPlacement: function (error, element) {
$(element).parents('.form-group').append(error);
}
});
//Custom Validations ===============================================================================
//Date
$.validator.addMethod('customdate', function (value, element) {
return value.match(/^\d\d\d\d?-\d\d?-\d\d$/);
},
'Please enter a date in the format YYYY-MM-DD.'
);
//Credit card
$.validator.addMethod('creditcard', function (value, element) {
return value.match(/^\d\d\d\d?-\d\d\d\d?-\d\d\d\d?-\d\d\d\d$/);
},
'Please enter a credit card in the format XXXX-XXXX-XXXX-XXXX.'
);
//==================================================================================================
});