Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I validate the length only when the field is not empty?

I have one text box, which I want to check for min-length, but it should check only when some text is there.

If someone has left that textbox empty, then it should not check for min-length.

Any suggestions?

like image 207
I-M-JM Avatar asked Feb 03 '11 12:02

I-M-JM


1 Answers

If you mean, that the text box can be left empty, then this may be your answer:

$("#your_text_box").rules("add", {
   required: false, // this means the field can be left empty
   minlength: 2
});

Using this, validator will skip this text box if it is empty. Hope this helps!

like image 167
aorcsik Avatar answered Oct 05 '22 22:10

aorcsik