-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathindex.html
More file actions
92 lines (85 loc) · 2.21 KB
/
Copy pathindex.html
File metadata and controls
92 lines (85 loc) · 2.21 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
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
87
88
89
90
91
92
<!DOCTYPE html>
<html>
<head>
<title>TinyValidation example</title>
<script src="jquery.js"></script>
<script src="../tinyvalidation.js"></script>
<script>
$(document).ready(function() {
var options = {
validateOnKeyUp: true,
onError: function(errors) {
console.log("el: " + this);
console.log(errors);
},
validators: {
zipCode: function(zip) {
var re = /^\d{5}(-?\d{4})?$/;
return re.test(zip) ? true : "Invalid zip code (ex. 12345 or 12345-1234)";
},
oneChecked: function(check) {
return $(this).closest('form').find('input[name="'+$(this).attr('name')+'"]:checked').length === 1;
}
}
};
$('form').tinyValidation(options);
});
</script>
<style>
label {
font-weight: bold;
}
label, input {
display: block;
}
input {
margin-bottom: 16px;
}
input[type="radio"] {
display: inline;
}
ol {
list-style-type: none;
}
.error {
border: 2px solid red;
}
.valid {
background-color: #99EE77;
}
</style>
</head>
<body>
<form>
<ol>
<li>
<label for="name">Name</label>
<input type="text" id="name" data-validate="notEmpty" />
</li>
<li>
<label for="email">Email</label>
<input type="text" id="email" data-validate="email, notEmpty" />
</li>
<li>
<label for="email_confirmation">Confirm email</label>
<input type="text" id="email_email" data-validate="email, notEmpty, matchesOtherField" data-match-field-selector="#email" />
</li>
<li>
<label for="bio">Bio</label>
<textarea id="bio" data-validate="notEmpty"></textarea>
</li>
<li>
<label for="zip">Zip</label>
<input type="text" id="zip" data-validate="zipCode" />
</li>
<li>
<label for="address">Address</label>
<input type="radio" name="address" value="home" data-validate="oneChecked">Home
<input type="radio" name="address" value="work" data-validate="oneChecked">Work
</li>
<li>
<input type="submit" />
</li>
</ol>
</form>
</body>