2

I have some custom validation I'd like to do with jQuery. jQuery validation comes out of the box with a 'required' class. This means that I can have a script declaring

$('form').validate()

and the next textbox will validate correctly, based on the class 'required' I add to it:

<input type="text" value="" name="flowstatus" id="flowstatus" class="required">

My new validation rule is: the text in a textbox should be between 15 and 50 chars long. Is there a way to create my own custom rule/class to implement something like

<input type="text" value="" name="flowstatus" id="flowstatus" class="from15to50">

Note: This is NOT what I need:

('form').validate({
    rules: {
        flowstatus: {required: true, minlength: 15, maxlength: 50}
}}); 

This last script is too tightly coupled to the fields I want to validate.

1 Answer 1

1

I'm pretty sure that you can add an attribute to the desired element defining its min and max lengths. Something like:

<input type="text" value="" name="flowstatus" id="flowstatus" class="required" minlength="15" maxlength="50">

I'm not quite sure about the custom class solution, however.

Sign up to request clarification or add additional context in comments.

Comments

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.