| 2 |
lars |
1 |
<!DOCTYPE html>
|
|
|
2 |
<html lang="en">
|
|
|
3 |
<head>
|
|
|
4 |
<meta charset="utf-8">
|
|
|
5 |
<title>Test for jQuery validate() plugin</title>
|
|
|
6 |
<link rel="stylesheet" media="screen" href="css/screen.css">
|
|
|
7 |
<script src="../lib/jquery.js"></script>
|
|
|
8 |
<script src="../dist/jquery.validate.js"></script>
|
|
|
9 |
<style>
|
|
|
10 |
.cmxform fieldset p.error label {
|
|
|
11 |
color: red;
|
|
|
12 |
}
|
|
|
13 |
div.container {
|
|
|
14 |
background-color: #eee;
|
|
|
15 |
border: 1px solid red;
|
|
|
16 |
margin: 5px;
|
|
|
17 |
padding: 5px;
|
|
|
18 |
}
|
|
|
19 |
div.container ol li {
|
|
|
20 |
list-style-type: disc;
|
|
|
21 |
margin-left: 20px;
|
|
|
22 |
}
|
|
|
23 |
div.container {
|
|
|
24 |
display: none
|
|
|
25 |
}
|
|
|
26 |
.container label.error {
|
|
|
27 |
display: inline;
|
|
|
28 |
}
|
|
|
29 |
form.cmxform {
|
|
|
30 |
width: 30em;
|
|
|
31 |
}
|
|
|
32 |
form.cmxform label.error {
|
|
|
33 |
display: block;
|
|
|
34 |
margin-left: 1em;
|
|
|
35 |
width: auto;
|
|
|
36 |
}
|
|
|
37 |
</style>
|
|
|
38 |
<script>
|
|
|
39 |
// only for demo purposes
|
|
|
40 |
$.validator.setDefaults({
|
|
|
41 |
submitHandler: function() {
|
|
|
42 |
alert("submitted! (skipping validation for cancel button)");
|
|
|
43 |
}
|
|
|
44 |
});
|
|
|
45 |
|
|
|
46 |
$().ready(function() {
|
|
|
47 |
$("#form1").validate({
|
|
|
48 |
errorLabelContainer: $("#form1 div.error")
|
|
|
49 |
});
|
|
|
50 |
|
|
|
51 |
var container = $('div.container');
|
|
|
52 |
// validate the form when it is submitted
|
|
|
53 |
var validator = $("#form2").validate({
|
|
|
54 |
errorContainer: container,
|
|
|
55 |
errorLabelContainer: $("ol", container),
|
|
|
56 |
wrapper: 'li'
|
|
|
57 |
});
|
|
|
58 |
|
|
|
59 |
$(".cancel").click(function() {
|
|
|
60 |
validator.resetForm();
|
|
|
61 |
});
|
|
|
62 |
});
|
|
|
63 |
</script>
|
|
|
64 |
</head>
|
|
|
65 |
|
|
|
66 |
<body>
|
|
|
67 |
<h1 id="banner"><a href="https://jqueryvalidation.org/">jQuery Validation Plugin</a> Demo</h1>
|
|
|
68 |
<div id="main">
|
|
|
69 |
<form method="get" class="cmxform" id="form1" action="">
|
|
|
70 |
<fieldset>
|
|
|
71 |
<legend>Login Form</legend>
|
|
|
72 |
<p>
|
|
|
73 |
<label>Username</label>
|
|
|
74 |
<input name="user" title="Please enter your username (at least 3 characters)" required minlength="3">
|
|
|
75 |
</p>
|
|
|
76 |
<p>
|
|
|
77 |
<label>Password</label>
|
|
|
78 |
<input type="password" maxlength="12" name="password" title="Please enter your password, between 5 and 12 characters" required minlength="5">
|
|
|
79 |
</p>
|
|
|
80 |
<div class="error">
|
|
|
81 |
</div>
|
|
|
82 |
<p>
|
|
|
83 |
<input class="submit" type="submit" value="Login">
|
|
|
84 |
</p>
|
|
|
85 |
</fieldset>
|
|
|
86 |
</form>
|
|
|
87 |
<!-- our error container -->
|
|
|
88 |
<div class="container">
|
|
|
89 |
<h4>There are serious errors in your form submission, please see below for details.</h4>
|
|
|
90 |
<ol>
|
|
|
91 |
<li>
|
|
|
92 |
<label for="email" class="error">Please enter your email address</label>
|
|
|
93 |
</li>
|
|
|
94 |
<li>
|
|
|
95 |
<label for="phone" class="error">Please enter your phone <b>number</b> (between 2 and 8 characters)</label>
|
|
|
96 |
</li>
|
|
|
97 |
<li>
|
|
|
98 |
<label for="address" class="error">Please enter your address (at least 3 characters)</label>
|
|
|
99 |
</li>
|
|
|
100 |
<li>
|
|
|
101 |
<label for="avatar" class="error">Please select an image (png, jpg, jpeg, gif)</label>
|
|
|
102 |
</li>
|
|
|
103 |
<li>
|
|
|
104 |
<label for="cv" class="error">Please select a document (doc, docx, txt, pdf)</label>
|
|
|
105 |
</li>
|
|
|
106 |
</ol>
|
|
|
107 |
</div>
|
|
|
108 |
<form class="cmxform" id="form2" method="get" action="">
|
|
|
109 |
<fieldset>
|
|
|
110 |
<legend>Validating a complete form</legend>
|
|
|
111 |
<p>
|
|
|
112 |
<label for="email">Email</label>
|
|
|
113 |
<input id="email" name="email" required type="email">
|
|
|
114 |
</p>
|
|
|
115 |
<p>
|
|
|
116 |
<label for="agree">Favorite Color</label>
|
|
|
117 |
<select id="color" name="color" title="Please select your favorite color!" required>
|
|
|
118 |
<option></option>
|
|
|
119 |
<option>Red</option>
|
|
|
120 |
<option>Blue</option>
|
|
|
121 |
<option>Yellow</option>
|
|
|
122 |
</select>
|
|
|
123 |
</p>
|
|
|
124 |
<p>
|
|
|
125 |
<label for="phone">Phone</label>
|
|
|
126 |
<input id="phone" name="phone" required type="number" rangelength="[2,8]">
|
|
|
127 |
</p>
|
|
|
128 |
<p>
|
|
|
129 |
<label for="address">Address</label>
|
|
|
130 |
<input id="address" name="address" required minlength="3">
|
|
|
131 |
</p>
|
|
|
132 |
<p>
|
|
|
133 |
<label for="avatar">Avatar</label>
|
|
|
134 |
<input type="file" id="avatar" name="avatar" required>
|
|
|
135 |
</p>
|
|
|
136 |
<p>
|
|
|
137 |
<label for="agree">Please agree to our policy</label>
|
|
|
138 |
<input type="checkbox" class="checkbox" id="agree" title="Please agree to our policy!" name="agree" required>
|
|
|
139 |
</p>
|
|
|
140 |
<p>
|
|
|
141 |
<input class="submit" type="submit" value="Submit">
|
|
|
142 |
<input class="cancel" type="submit" value="Cancel">
|
|
|
143 |
</p>
|
|
|
144 |
</fieldset>
|
|
|
145 |
</form>
|
|
|
146 |
<div class="container">
|
|
|
147 |
<h4>There are serious errors in your form submission, please see details above the form!</h4>
|
|
|
148 |
</div>
|
|
|
149 |
<a href="index.html">Back to main page</a>
|
|
|
150 |
</div>
|
|
|
151 |
</body>
|
|
|
152 |
</html>
|