/ Published in: JavaScript
CSS:
.error
style the error class
Form HTML:
class="required"
makes the input field required
minlength="2"
makes the field require at least 2 characters
.error
style the error class
Form HTML:
class="required"
makes the input field required
minlength="2"
makes the field require at least 2 characters
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
<html> <head> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js"></script> <script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.8.1/jquery.validate.min.js"></script> <script type="text/javascript"> $(document).ready(function() { $('#my_form').validate(); }) </script> <style type="text/css"> label { display:block; } input { display:block; } input.error { border: 1px solid red; } </style> </head> <body> <form id="my_form" action="" method="post"> <label>First Name</label> <input id="my_firstname" class="required" minlength="2" /> <label>Last Name</label> <input id="my_lastname" class="required" minlength="2" /> <label>Email</label> <input id="my_email" class="required email" /> </form> </body> </html>