jQuery - Live Validation Plug-ins

前端 未结 5 1811
梦如初夏
梦如初夏 2021-02-04 14:26

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 Validati

5条回答
  •  礼貌的吻别
    2021-02-04 14:47

    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"
        }
    });
    

提交回复
热议问题