Johnny Klassy
Johnny Klassy

Reputation: 1650

jQuery validate only if non-blank

I'm on the latest jQuery version 1.6.2 and validate 1.8. What's the syntax for verifying a an optional phone field if non-blank? This doesn't trigger it

<%= f.text_field :fax, :class => "phoneUS" %>

It only gets triggered if I add required to class like such

<%= f.text_field :fax, :class => "required phoneUS" %>

Upvotes: 1

Views: 556

Answers (1)

Jayendra
Jayendra

Reputation: 52809

Remove the required class so that it is optional.
use the minlength equals 1 to check if its not empty.

<%= f.text_field :fax, :class => "phone", :minlength => "1" %>

Upvotes: 1

Related Questions