0

I am using the jQuery validation plugin and it works correctly , but I have a problem checking email. I receive true or false dependant on if email exists or not. However I don't know how to change the state of validation in the form, because I can't pass the validation.

email: {
    required: true,
    email: true,
    remote: {
        url: "checkEmail",
        type: "get",
        success: function(data){
            if (data.msg == true) {
                ///Email avaliable////
                console.log("OK");
            } else {
                /////Email taken///
                console.log("NO");
            }
        }
    },
},

Could anyone help me?

Rory McCrossan
  • 331,213
  • 40
  • 305
  • 339
jc1992
  • 644
  • 3
  • 10
  • 24
  • To verify if email exists please look here: http://stackoverflow.com/questions/565504/how-to-check-if-an-email-address-exists-without-sending-an-email But, do you want to do that, or do you want to validate if given text is an email address? – eithed May 25 '16 at 09:29
  • Check this for jquery remote validation https://www.sitepoint.com/jquery-ajax-validation-remote-rule/ – Ankur Bhadania May 25 '16 at 09:31
  • AFAIK, you should put the changes that you want to happen in the `if else` block. – Ciprianis May 25 '16 at 09:31
  • https://www.sitepoint.com/jquery-ajax-validation-remote-rule – Rory McCrossan May 25 '16 at 09:32

1 Answers1

0

Considering that the ajax call returns true or false based on data , you can try the following code snippet of email rule and messages rule .

email: {
    required: true,
    email: true,
    remote: {
      url: "checkEmail",
      type: "post",
      data: {
        email: function() {
          return $('#formID :input[name="email"]').val();
        }
      }
    }
  },
    
  messages: {
    email: {
      required: "Please enter your email address.",
      email: "Please enter a valid email address.",
      remote: jQuery.validator.format("{0} is already taken.")
    }
  }