| 21627 |
kshitij.so |
1 |
var Script = function () {
|
|
|
2 |
|
|
|
3 |
$.validator.setDefaults({
|
|
|
4 |
submitHandler: function() { alert("submitted!"); }
|
|
|
5 |
});
|
|
|
6 |
|
|
|
7 |
$().ready(function() {
|
|
|
8 |
// validate the comment form when it is submitted
|
|
|
9 |
$("#feedback_form").validate();
|
|
|
10 |
|
|
|
11 |
// validate signup form on keyup and submit
|
|
|
12 |
$("#register_form").validate({
|
|
|
13 |
rules: {
|
|
|
14 |
fullname: {
|
|
|
15 |
required: true,
|
|
|
16 |
minlength: 6
|
|
|
17 |
},
|
|
|
18 |
address: {
|
|
|
19 |
required: true,
|
|
|
20 |
minlength: 10
|
|
|
21 |
},
|
|
|
22 |
username: {
|
|
|
23 |
required: true,
|
|
|
24 |
minlength: 5
|
|
|
25 |
},
|
|
|
26 |
password: {
|
|
|
27 |
required: true,
|
|
|
28 |
minlength: 5
|
|
|
29 |
},
|
|
|
30 |
confirm_password: {
|
|
|
31 |
required: true,
|
|
|
32 |
minlength: 5,
|
|
|
33 |
equalTo: "#password"
|
|
|
34 |
},
|
|
|
35 |
email: {
|
|
|
36 |
required: true,
|
|
|
37 |
email: true
|
|
|
38 |
},
|
|
|
39 |
topic: {
|
|
|
40 |
required: "#newsletter:checked",
|
|
|
41 |
minlength: 2
|
|
|
42 |
},
|
|
|
43 |
agree: "required"
|
|
|
44 |
},
|
|
|
45 |
messages: {
|
|
|
46 |
fullname: {
|
|
|
47 |
required: "Please enter a Full Name.",
|
|
|
48 |
minlength: "Your Full Name must consist of at least 6 characters long."
|
|
|
49 |
},
|
|
|
50 |
address: {
|
|
|
51 |
required: "Please enter a Address.",
|
|
|
52 |
minlength: "Your Address must consist of at least 10 characters long."
|
|
|
53 |
},
|
|
|
54 |
username: {
|
|
|
55 |
required: "Please enter a Username.",
|
|
|
56 |
minlength: "Your username must consist of at least 5 characters long."
|
|
|
57 |
},
|
|
|
58 |
password: {
|
|
|
59 |
required: "Please provide a password.",
|
|
|
60 |
minlength: "Your password must be at least 5 characters long."
|
|
|
61 |
},
|
|
|
62 |
confirm_password: {
|
|
|
63 |
required: "Please provide a password.",
|
|
|
64 |
minlength: "Your password must be at least 5 characters long.",
|
|
|
65 |
equalTo: "Please enter the same password as above."
|
|
|
66 |
},
|
|
|
67 |
email: "Please enter a valid email address.",
|
|
|
68 |
agree: "Please accept our terms & condition."
|
|
|
69 |
}
|
|
|
70 |
});
|
|
|
71 |
|
|
|
72 |
// propose username by combining first- and lastname
|
|
|
73 |
$("#username").focus(function() {
|
|
|
74 |
var firstname = $("#firstname").val();
|
|
|
75 |
var lastname = $("#lastname").val();
|
|
|
76 |
if(firstname && lastname && !this.value) {
|
|
|
77 |
this.value = firstname + "." + lastname;
|
|
|
78 |
}
|
|
|
79 |
});
|
|
|
80 |
|
|
|
81 |
//code to hide topic selection, disable for demo
|
|
|
82 |
var newsletter = $("#newsletter");
|
|
|
83 |
// newsletter topics are optional, hide at first
|
|
|
84 |
var inital = newsletter.is(":checked");
|
|
|
85 |
var topics = $("#newsletter_topics")[inital ? "removeClass" : "addClass"]("gray");
|
|
|
86 |
var topicInputs = topics.find("input").attr("disabled", !inital);
|
|
|
87 |
// show when newsletter is checked
|
|
|
88 |
newsletter.click(function() {
|
|
|
89 |
topics[this.checked ? "removeClass" : "addClass"]("gray");
|
|
|
90 |
topicInputs.attr("disabled", !this.checked);
|
|
|
91 |
});
|
|
|
92 |
});
|
|
|
93 |
|
|
|
94 |
|
|
|
95 |
}();
|