forked from soitgoes/FormWarden
-
Notifications
You must be signed in to change notification settings - Fork 0
/
validation_only.html
115 lines (102 loc) · 3.64 KB
/
validation_only.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
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
<!DOCTYPE HTML>
<html>
<head>
<script src="jquery-1.6.1.min.js" type="text/javascript"></script>
<script src="formwarden.js" type="text/javascript"></script>
<script src="jquery.formwarden.js" type="text/javascript"></script>
<style>
.invalid input, .invalid select, .invalid textarea{
border:solid 2px #f00;
}
.invalid{
color:#f00;
}
</style>
</head>
<body>
<form method="post" action="validation_only.html" >
<p>
<label>Email: <input type="text" name="email" /></label>
</p>
<p>
<label>First Name: <input type="text" name="firstName" /></label>
</p>
<p>
<label>UserName: <input type="text" name="userName" /></label>
</p>
<p>
<label>InnCode: <input type="text" name="inncode" /></label>
</p>
<p>
<select name="select">
<option value="">select one...</option>
<option>abc</option>
<option>def</option>
</select>
</p>
<p>
<select multiple name="multi">
<option>aaa</option>
<option>abc</option>
<option>def</option>
</select>
</p>
<p>
<input type="radio" name="radio" value="1" /> Choice 1
<input type="radio" name="radio" value="2" /> Choice 2
</p>
<p>
<input type="checkbox" name="check" value="1" /> Choice A
<input type="checkbox" name="check" value="2" /> Choice B
</p>
<p>
<textarea name="textarea"></textarea>
</p>
<ul class="validation_summary">
</ul>
<input id="submit_button" type="submit" value="Go" name="submit_button"/>
</form>
<script type="text/javascript">
$(function(){
var validationOptions=
{
//override the error processing
/*
processErrors: function(results){
for(var item in results.fields){
var thing = results.fields[item];
if (!thing.valid){
alert(thing.error);
}
}
},
*/
//disable/enable blur
//enableBlur:false, //defaults to true
//provide custom validators if desired
//specify the validation summary container to use
// validationSummary: ".validation_summary" ,
before: function(form){ console.log(form)},
after: function(results){console.log(results)},
validators : {"inncode":function(value){return value.match(/^\d{5}$/);}}, //not required
fields:{
"inncode":[{isValid:"required", message:"Inncode is required"},
{isValid:"inncode", message:"Inncode must be 5 digits"}],
"userName":[{isValid:/^[a-z]{3,}?$/i, message:"UserName must be greater than 3 characters and not include any numbers"},
{isValid:"required", message:"UserName is required"}],
"email":[{isValid:"required", message:"Email is required"},
{isValid:"email", message:"Email must be valid"}],
"firstName":[{isValid: "required", message: "First Name is required"},
{isValid:function(value, form){ return value.length < 25; }, message:"First Name must be less than 25 characters"}],
"select":[{isValid: "required", message: "Select is required"}],
"radio":[{isValid: "required", message: "radio is required"}],
"check":[{isValid: "required", message: "check is required"}],
"multi":[{isValid: "required", message: "multi is required"}],
"textarea":[{isValid: "required", message: "textarea is required"}]
}
};
$("form").validation(validationOptions);
});
</script>
</body>
</html>