Submitted by boydjd on Fri, 03/14/2008 - 14:03
Posted in
Form validation is ridiculously easy with JQuery and the JQuery Validate plugin. You'll need JQuery, Validate, and Delegate.
Throw JQuery and Validate in your page somewhere ...
<script src="js/jquery.js" type="text/javascript"></script>
<script src="js/jquery.validate.js" type="text/javascript"></script>
<script src="js/jquery.validate.js" type="text/javascript"></script>
Then throw this somewhere, and it'll validate a form with an id of "form-name".
<script type="text/javascript>
$().ready(function() {
// validate signup form on keyup and submit
$("#form-name").validate({
rules: {
sender_name: "required",
sender_email: {
required: true,
email: true
},
recipients: {
required: true,
email: true
}
},
messages: {
sender_name: "<span style='color:red;font-weight:bold'>*</span>",
sender_email: "<span style='color:red;font-weight:bold'>*</span>",
recipients: "<span style='color:red;font-weight:bold'>*</span>"
}
});
});
</script>
$().ready(function() {
// validate signup form on keyup and submit
$("#form-name").validate({
rules: {
sender_name: "required",
sender_email: {
required: true,
email: true
},
recipients: {
required: true,
email: true
}
},
messages: {
sender_name: "<span style='color:red;font-weight:bold'>*</span>",
sender_email: "<span style='color:red;font-weight:bold'>*</span>",
recipients: "<span style='color:red;font-weight:bold'>*</span>"
}
});
});
</script>
Neat.
Trackback URL for this post:
http://www.jbip.net/trackback/36
