3

I'm trying to validate a form having an email address whose prop is set to 'true' as shown:

$( "#myform" ).validate({
  rules: {
   field: {
    required: true,
     email: true
    }
  }
});

I checked out the jquery plugin http://jqueryvalidation.org/email-method/ and i see that the email address gets verified only until the '@' symbol(example in the above link). I'm making a email validation script that basically just checks for complete emailaddress including the 'dot' at the end. any ideas how to achieve this??

http://jsfiddle.net/dbnkahee/1/

user1234
  • 3,000
  • 4
  • 50
  • 102

1 Answers1

7

You can add jQuery.validator.addMethod with your Regex try this:-

jQuery.validator.addMethod("emailfull", function(value, element) {
 return this.optional(element) || /^([a-z\d!#$%&'*+\-\/=?^_`{|}~\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+(\.[a-z\d!#$%&'*+\-\/=?^_`{|}~\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+)*|"((([ \t]*\r\n)?[ \t]+)?([\x01-\x08\x0b\x0c\x0e-\x1f\x7f\x21\x23-\x5b\x5d-\x7e\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]|\\[\x01-\x09\x0b\x0c\x0d-\x7f\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))*(([ \t]*\r\n)?[ \t]+)?")@(([a-z\d\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]|[a-z\d\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF][a-z\d\-._~\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]*[a-z\d\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])\.)+([a-z\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]|[a-z\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF][a-z\d\-._~\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]*[a-z\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])\.?$/i.test(value);
}, "Please enter valid email address!");

And then use it as:-

$( "#myform" ).validate({
  rules: {
  field: {
   required: true,
   emailfull: true
 }
 }
});

RegEx by aSeptik see this answer

Demo

Other RegEx

Community
  • 1
  • 1
Umesh Sehta
  • 10,555
  • 5
  • 39
  • 68
  • Any benefit between this answer and your linked "Other RegEx" example? The linked one seems shorter and more concise. – Eckstein May 02 '18 at 01:07