JQuery is my all time favorite JavaScript library, it's so simple to use and incredibly powerful, but if you include all the plugins that are available, I just don't think that you would find a better tool for client side scripting.
My favorite validation plugin is the 'Validation Plugin', let me give you an example of how it is used:
Lets say you have a signup form, you want the user to select a user name, a password with confirmation and an email address, assume all of this is inside a form tag named 'signup'.
All of the HTML input element ids are 'Password', 'ConfirmPassword', 'Email'.
The JavaScript would be:
<script type="text/javascript"> $().ready(function() { $("#signup").validate({ rules: { UserName: { required: true, minLength: 2, remote: "/Account/CheckUserName" }, Password: { required: true, minLength: 2 }, ConfirmPassword: { required: true, minLength: 5, equalTo: "#Password" }, Email:{ required: true, email: true, remote: "/Account/CheckEmail" } }, messages: { UserName: { required: "Please enter a username", minLength: "Your username must consist of at least 2 characters", remote: jQuery.format("{0} is already in use") }, Password: { required: "Please enter a password", minLength: "Your password must consist of at least 2 characters" }, ConfirmPassword: { required: "Please provide a password", minLength: "Your password must be at least 2 characters long", equalTo: "Please enter the same password as above" }, Email: { required: "Please enter your email address", minLength: "Please enter a valid email address", remote: jQuery.format("{0} is already in use") } } }); }); </script>
Now notice how I used the remote property with '/Account/CheckEmail' and '/Account/CheckUserName', these are URL's that will be called by the client side JavaScript, they will pass along the current value of the textbox, so you could write server side code to validate the input, an ASP.NET MVC Controller Method could look like:
public JsonResult CheckUserName(string username) { return Json(CheckValidUsername(username)); }
Notice the use of a JsonResult, The ASP.NET MVC framework is great for this type of thing, combine both JQuery and the MVC framework and you have a powerful combination, Jeff Atwood has come to the same conclusion and used both of these tools to build stackoverflow.com.
All of the above code is so clean and easy to read, can you ever remember saying that about JavaScript code?