Samizdis
Samizdis

Reputation: 1671

JQuery validate not implementing 'required' in email field

I've a simple HTML input:

<input id="email" name="email" value="" type="email">

and validate it using JQuery validate:

$('form').validate({
    rules: {
      email: {
        required: 'true',
        email: 'true'
      }
    }
});

The rules are applied, I can see them in $('#email').rules(). However when I later run $('#email').valid() or $('form').valid() the input is marked as valid when empty, but invalid when an invalid email address is entered.

How do I ensure the input is invalid when empty?

Relevant JSfiddle: https://jsfiddle.net/ycypuy86/

Upvotes: 1

Views: 42

Answers (1)

Mark Redman
Mark Redman

Reputation: 24535

I usually set these without quotes?

rules: {
      email: {
        required: true,
        email: true
      }
    }

remove quotes on your fiddle and it works.

Upvotes: 4

Related Questions