Repository navigation
Expand file tree
/
Copy pathindex.html
More file actions
274 lines (225 loc) · 10.6 KB
/
Copy pathindex.html
File metadata and controls
274 lines (225 loc) · 10.6 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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
<!DOCTYPE html>
<head>
<title>h5Validate - The HTML5 Form Validation Plugin for jQuery</title>
<script type="text/javascript" src="http://js.getexceptional.com/exceptional.js"></script>
<script type="text/javascript">
Exceptional.setKey('e778cbe66170d28dc9233629cec1edba8c98113a');
</script>
<style type="text/css">
body {
width:960px;
margin:0 auto;
font-size:14pt;
}
label {
font-weight:bold;
margin-right:1em;
}
h1 {
font-size: 2.5em;
}
h2 {
font-size:2em;
margin-top:2em;
}
dt {
font-weight:bold;
font-family:monospace;
line-height:100%;
}
.ui-state-error {
background-color:#BB1100;
color:white;
}
.block {
display:block;
margin:1em;
}
#form4 input, label {
float:left;
}
.message {
margin-left:1em;
width:20em;
border:1px;
padding:2px;
float:left;
font-size:10pt;
}
.black {
background-color:#111111;
color:silver;
}
.button {
border-top: 1px solid #96d1f8;
background: #65a9d7;
background: -webkit-gradient(linear, left top, left bottom, from(#3e779d), to(#65a9d7));
background: -moz-linear-gradient(top, #3e779d, #65a9d7);
padding: 13.5px 27px;
-webkit-border-radius: 17px;
-moz-border-radius: 17px;
border-radius: 17px;
-webkit-box-shadow: rgba(0,0,0,1) 0 1px 0;
-moz-box-shadow: rgba(0,0,0,1) 0 1px 0;
box-shadow: rgba(0,0,0,1) 0 1px 0;
text-shadow: rgba(0,0,0,.4) 0 1px 0;
color: white;
font-size: 24px;
font-family: 'Lucida Grande', Helvetica, Arial, Sans-Serif;
text-decoration: none;
vertical-align: middle;
margin-bottom:2em;
}
.button:hover {
border-top-color: #28597a;
background: #28597a;
color: #ccc;
}
.button:active {
border-top-color: #1b435e;
background: #1b435e;
}
.announce {
border-left: 1px solid #afafaf;
background-color: #ffefff;
color: black;
margin-left: 3em;
padding-top:.1em;
padding-bottom: .1em;
padding-left: 1em;
padding-right: 1em;
}
</style>
</head>
<body>
<h1>h5Validate - HTML5 Form Validation for jQuery</h1>
<a class="button" href="http://github.com/dilvie/h5Validate/archives/master">Download from Github</a>
<br /><br />
<p>If you want to contribute, feel free to <a href="http://github.com/dilvie/h5Validate">fork the project on Github</a>.</p>
<p>A jQuery plugin that understands HTML5 forms and knows how to validate them, even in browsers that don't yet support HTML5.</p>
<p>In browsers that do support HTML5, h5Validate adds some much-needed features, such as the ability to customize the user interface when an input fails validation.</p>
<div class="announce">
<p><h3>Important update: A known cross-browser issue was resolved in v0.3.3:</h3></p>
<p>The required attribute was not being handled properly in some (non-webkit) browsers, including IE and Firefox.</p>
<p>If you are using a version older than 0.3.3, an upgrade is highly recommended.</p>
<p><strong>Verified support:</strong> IE 9, 8, 7, 6, Chrome, Firefox, Safari, and Opera. Tested on Windows 7 and Mac.</p>
<p><strong>Verified mobile support:</strong> iPhone, Android, Palm WebOS</p>
<p>Many thanks to ajpiano on Freenode #jquery for helpful suggestions.</p>
</div>
<h2>Jump Start</h2>
<p>Copy and paste this at the end of the body on any page with an HTML5 form. If html5 validation rules exist in the form, you're in business!</p>
<script src="http://gist.github.com/607687.js?file=h5Validate-loader-part.html"></script>
<h2>Features</h2>
<h3>HTML5 required attribute. e.g.</h3>
<form id="form1" class="h5-defaults">
<label for="name">Your Name:*</label>
<input id="name" name="name" type="text" placeholder="Bob" title="Your name is required." required />
<p><em>Hint: Select it, then click somewhere else without typing anything.</em></p>
</form>
<h4>Source:</h4>
<script src="http://gist.github.com/607690.js?file=h5-required-demo-part.html"></script>
<h3>HTMTL5 pattern attribute. e.g.</h3>
<form id="form2" class="h5-defaults">
<label for="birthdate">Your Birth Date:</label>
<input id="name" name="name" type="text" placeholder="mm/dd/yyyy" title="mm/dd/yyyy" pattern="(0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])[- /.](19|20)\d\d" />
</form>
<p><em>Hint: It's expecting mm/dd/yyyy. Try typing "jQuery rocks!" instead.</em></p>
<h4>Source:</h4>
<script src="http://gist.github.com/607739.js?file=h5-pattern-demo-part.html"></script>
<h3>Pattern Library</h3>
<p>Sometimes, you'll want to re-use the same validation pattern for several elements on a page. You could copy and paste the same pattern over and over again to a bunch of different form fields, but what happens if you discover a bug in the pattern? Fix it and repeat the whole copy and paste process?</p>
<p>A better solution is to attach the pattern with a class selector. Use <a href="#addPatterns"><code>$.h5Validate.addPatterns()</code></a> to add your pattern, make sure the classPrefix variable is set correctly (it's <code>h5-</code> by default), and add the class to the input fields.</p>
<h3>Error Messages</h3>
<p>Error divs should be hidden in the HTML with <code>display:none;</code> -- h5Validate shows them when the corresponding field is marked invalid.</p>
<form id="form4" class="h5-defaults">
<label for="FirstName">Your Name:*</label>
<input id="FirstName" type="text" data-h5-errorid="invalid-FirstName" title="Required: Please provide your first name." required />
<div id="invalid-FirstName" class="ui-state-error message" style="display:none;">Default error: Please enter your name.</div>
</form>
<h2>Options</h2>
<p>There are a <em>ton</em> of options you can override by passing key: value pairs when you call .h5Validate(). For example, we can change the CSS class that indicates validation errors:</p>
<form id="black">
<label for="name2">Your Name:*</label>
<input id="name2" name="name2" type="text" placeholder="Bob" title="Your name is required." required />
<p><em>Hint: Select it, then click somewhere else without typing anything.</em></p>
</form>
<h4>Source:</h4>
<script src="http://gist.github.com/607750.js?file=h5-setting-options-part.html"></script>
<dl>
<dt>errorClass</dt><dd><p>Custom CSS class for validation errors.</p></dd>
<dt>validClass</dt><dd><p>Custom CSS class to mark a field validated.</p></dd>
<dt>errorAttribute</dt><dd><p>An html attribute that stores the ID of the error message container for this element. It's set to data-h5-errorid by default. <em>Note: The data- attribute prefix is a new feature of HTML5, used to store an element's meta-data.</em> e.g.</p>
<code class="block"><input id="name" data-h5-errorid="nameError" required ></code>
</dd>
<dt>kbSelectors</dt><dd><p>A list of CSS selectors for attaching keyboard-oriented events. Default:</p>
<code class="block">kbSelectors: ':text, :password, select, textarea'</code>
</dd>
<dt>focusout, focusin, change, keyup</dt><dd><p>(Events) These are the "keyboard oriented" events. Better to think of them as non-mouse-specific events. Set them to "true" if you want them to trigger a field validation. Defaults:</p>
<code class="block">focusout: true,<br />
focusin: false,<br />
change: false,<br />
keyup: true</code>
</dd>
<dt>mSelectors</dt><dd><p>A list of CSS selectors for attaching "mouse oriented" events. Default:</p>
<code class="block">mSelectors: ':radio, :checkbox, select, option'</code>
</dd>
<dt>click</dt><dd><p>(Event) The only default mouse-oriented event. Since it probably makes little sense to trigger validation on other mouse events, I'll leave it to you to figure out how to enable them.</p>
<p><em>Note: The click event isn't just for the mouse. It will trigger for keyboard and touch screen interactions, too.</em></p>
<code class="block">click: true</code>
</dd>
<div class="method">
<h2>Methods</h2>
<dl>
<a name="addPatterns" />
<dt>$.h5Validate.addPatterns(patterns)</dt>
<dd><p>Take a map of pattern names and HTML5-compatible regular
expressions, and add them to the patternLibrary. Patterns in
the library are automatically assigned to HTML element pattern
attributes for validation.</p>
<dl><dt>{object} patterns</dt><dd><p>A map of pattern names and
HTML5 compatible regular expressions.</p></dd></dl>
<h3>Demo</h3>
<form id="form3" class="h5-defaults">
<label for="phone">Your Phone Number:</label>
<input class="h5-phone" id="phone" name="phone" type="text" placeholder="555-555-5555" title="555-555-5555" />
</form>
<h3>Source:</h3>
<script src="http://gist.github.com/612886.js?file=h5-class-selectors-part.html"></script>
<p>The <code>class="h5-phone"</code> bit is the part doing the magic. The <code>h5-</code> prefix tells you that this class is a handle that we can use to attach validation rules to. Internally, we just tack this prefix to the front of the pattern names to get the right selectors.</p>
<p>In your JavaScript, specify the pattern name <em>without</em> the class prefix. Keeping the prefix off lets us easily share and re-use pattern libraries between projects.</p>
<script src="http://gist.github.com/612886.js?file=h5-custom-pattern-part.js"></script>
</dd>
<br/>
<dt>$.h5Validate.validValues(selector, values)<dt>
<dd><p>Take a valid jQuery selector, and a list of valid values to
validate against.</p>
<p>If the user input isn't in the list, validation fails.</p>
<dl>
<dt>{String} selector</dt><dd><p>Any valid jQuery selector.</p></dd>
<dt>{Array} values</dt><dd><p>A list of valid values to validate selected
fields against.</p></dd>
</dl>
</dl>
</div>
<h3>Coming soon!</h3>
<dl>
<dt>submit</dt><dd><p>(Event) Set true to trigger validation on submit. Submit needs a special handler, because it needs to check that all fields are valid, optionally save data, and optionally submit the form. Will have Ajax, get, and post. Default:</p>
<code class="block">submit: true</code>
</dd>
<dt>messages</dt><dd><p>Error messages to display. This is here so that you can easily swap them out. You might want to write your own error messages, or provide language translations.</p></dd>
</dl>
<script src="lib/jquery/jquery-1.4.2.min.js"></script>
<script src="jquery.h5validate.js"></script>
<script>
$(document).ready(function () {
$.h5Validate.addPatterns({
phone: /([\+][0-9]{1,3}([ \.\-])?)?([\(]{1}[0-9]{3}[\)])?([0-9A-Z \.\-]{1,32})((x|ext|extension)?[0-9]{1,4}?)/
});
$('form.h5-defaults').h5Validate();
$('#black').h5Validate({
errorClass:'black'
});
});
</script>
</body>
</html>