Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery - Live Validation Plug-ins

I'm looking for a plugin for jQuery that can validate as a key is pressed and after it loses focus (text boxes).

I'm currently using jVal - jQuery Form Field Validation Plugin. It works pretty good. The only issue I have is that I can only use a generic error message.

For example: I need a string to between 2 and 5 characters. If its too short I would like to display an error message that indicates it to short, equally if its too long. I know I could display an error message that requires the string to between 2 and 5 characters. The validation that is being done is more complicated.

Any ideas of other validators or how I could use this plug-in to display unique error messages.


Edit:

The validation tool needs to prevent particular letters or numbers and not require a form.

Thanks

like image 533
Brad8118 Avatar asked Oct 16 '08 15:10

Brad8118


2 Answers

This one looks like it would fit your description:

  • jQuery plugin:validation (Homepage)
  • demo
  • API docs

Here's a snippet of code copied from the source of the demo:

// validate signup form on keyup and submit
$("#signupForm").validate({
    rules: {
        firstname: "required",
        lastname: "required",
        username: {
            required: true,
            minlength: 2
        },
        password: {
            required: true,
            minlength: 5
        },
        confirm_password: {
            required: true,
            minlength: 5,
            equalTo: "#password"
        },
        email: {
            required: true,
            email: true
        },
        topic: {
            required: "#newsletter:checked",
            minlength: 2
        },
        agree: "required"
    },
    messages: {
        firstname: "Please enter your firstname",
        lastname: "Please enter your lastname",
        username: {
            required: "Please enter a username",
            minlength: "Your username must consist of at least 2 characters"
        },
        password: {
            required: "Please provide a password",
            minlength: "Your password must be at least 5 characters long"
        },
        confirm_password: {
            required: "Please provide a password",
            minlength: "Your password must be at least 5 characters long",
            equalTo: "Please enter the same password as above"
        },
        email: "Please enter a valid email address",
        agree: "Please accept our policy"
    }
});
like image 96
hasseg Avatar answered Oct 25 '22 17:10

hasseg


Try this:

http://www.geektantra.com/2009/09/jquery-live-form-validation/

like image 33
GeekTantra Avatar answered Oct 25 '22 18:10

GeekTantra