-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
86 lines (74 loc) · 2.4 KB
/
index.html
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<!DOCTYPE html>
<html>
<head>
<title>jQuery Validation Test</title>
</head>
<body>
<form id="client-search" method="post" action="index.html">
<input type="hidden" id="mutually-exclusive-rule" name="mutually-exclusive-rule" />
<label for="file-number">File Number</label>
<input type="text" id="file-number" name="file-number" />
<strong>or</strong>
<label for="uin">UIN</label>
<input type="text" id="uin" name="uin" />
<hr />
<strong>OR</strong>
<hr />
<label for="surname">Surname</label>
<input type="text" id="surname" name="surname" />
<label for="first-name">First Name</label>
<input type="text" id="first-name" name="first-name" />
<hr />
<input type="submit" value="Search" />
<input type="button" value="Clear" />
</form>
<script src="https://code.jquery.com/jquery-3.2.1.js" integrity="sha256-DZAnKJ/6XZ9si04Hgrsxu/8s717jcIzLy3oi35EouyE=" crossorigin="anonymous"></script>
<script src="jquery.validate.js"></script>
<script src="additional-methods.js"></script>
<script type="text/javascript">
$(document).ready(function() {
var hasIdSearch = function() {
return $("#file-number").is(":not(:blank)") || $("#uin").is(":not(:blank)");
}
var hasBioSearch = function() {
return $("#surname").is(":not(:blank)") || $("#first-name").is(":not(:blank)");
}
$.validator.addMethod("mutuallyExclusive", function(value, element, param) {
if((hasIdSearch() && hasBioSearch()) || (!hasIdSearch() && !hasBioSearch()))
return false;
return true;
},
function() {
return 'Please enter a valid search combination';
});
$.validator.addMethod("xor", function(value, element, param) {
var otherValue = $(param[0]).val();
return this.optional(element) || ((value && !otherValue) || (!value && otherValue));
},
jQuery.validator.format('{1}'));
$("#client-search").validate({
onkeyup: false,
ignore: "",
rules: {
"file-number": {
pattern: /^([A-Za-z])([A-Za-z ]{1,3})([0-9]{1,6})([A-Za-z]?)$/,
xor: ["#uin", "Please enter only a file number or UIN"]
},
"uin": {
digits: true,
xor: ["#file-number", "Please enter only a file number or UIN"]
},
"surname": {
required: function() {
return !hasIdSearch() && hasBioSearch();
}
},
"mutually-exclusive-rule": {
mutuallyExclusive: true
}
}
});
});
</script>
</body>
</html>