-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathdeclarative.html
76 lines (68 loc) · 2.54 KB
/
declarative.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
<!DOCTYPE html>
<html lang="en">
<head>
<title>callback validator - FormValidation</title>
<meta charset="utf-8" />
<meta content="width=device-width,initial-scale=1" name="viewport" />
</head>
<body>
<form id="testForm" method="post">
<div>
<input
type="text"
name="pwd"
data-fv-callback="true"
data-fv-callback___callback="validatePassword"
data-fv-callback___message="Password is not valid"
/>
</div>
<div>
<button type="submit">Submit</button>
</div>
</form>
<script src="/vendors/@form-validation/umd/bundle/popular.min.js"></script>
<script>
function validatePassword(input) {
const value = input.value;
if (value === '') {
return { valid: true };
}
if (value.length < 8) {
return {
valid: false,
message: 'Password must have at least 8 characters',
};
}
if (value === value.toLowerCase()) {
return {
valid: false,
message: 'Password must have at least one uppercase character',
};
}
if (value === value.toUpperCase()) {
return {
valid: false,
message: 'Password must have at least one lowercase character',
};
}
if (value.search(/[0-9]/) < 0) {
return {
valid: false,
message: 'Password must have at least one digit',
};
}
return { valid: true };
}
document.addEventListener('DOMContentLoaded', function (e) {
FormValidation.formValidation(document.getElementById('testForm'), {
plugins: {
message: new FormValidation.plugins.Message(),
trigger: new FormValidation.plugins.Trigger(),
submitButton: new FormValidation.plugins.SubmitButton(),
declarative: new FormValidation.plugins.Declarative(),
},
});
});
</script>
</body>
</html>