3

I have the JQuery validations below that just ensure that something is written within the input fields, I also have maxlength in the html.

However, I was hoping someone could shed some light on the situation and inform me on how I can add some type of minlength to the jquery code below so I don't require to do any additional functions?

 $('#form1').submit(function (e) {
    e.preventDefault();
}).validate({
    rules: {
        txtusername: {
            required: true
        },
        txtfirstname: {
            required: true
        },
        txtemail: {
            required: true
        },
        txtpassword: {
            required: true
        },
        passwordconfirm: {
            required: true
        }
    },
    messages: {
        txtusername: {
            required: "Please enter your Username."
        },
        txtfirstname: {
            required: "Please enter your First Name."
        },
        txtemail: {
            required: "Please enter your Email."
        },
        txtpassword: {
            required: "Please enter your Password."
        },
        passwordconfirm: {
            required: "Please enter your password again."
        }
    },
    errorPlacement: function (error, element) {
        error.appendTo(element.parent().prev());
    },
    submitHandler: function (form, user) {

        CheckUser(form);
        return false;
    }
});

Example HTML -

<div data-role="fieldcontainer">
            <label for="txtusername" data-theme="d">Username:</label>
            <input type="text" id="txtusername" name="txtusername" maxlength="12"  placeholder="Enter Username"/>
        </div>

1 Answer 1

2

You can use like below:

rules:{
    txtusername: {
        required: true,
        minlength: 3
    },
}
Sign up to request clarification or add additional context in comments.

1 Comment

I did try this early, but the reason it wasn't working was because I left out the comma after true :S. Thanks for your help buddy!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.