My script javascript is like this :
email: {
         required: true,
         email: true          
},
When in the textfield email, I write : chelsea@gmail without .com, it's valid.
Any solution to solve my problem?
Thank you
My script javascript is like this :
email: {
         required: true,
         email: true          
},
When in the textfield email, I write : chelsea@gmail without .com, it's valid.
Any solution to solve my problem?
Thank you
To validate whether an email address is of the name@domain.tld format you can use the following regular expression:
var emailExp = new RegExp(/^\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b$/i);
This regular expression accepts only email addresses that contain an @-sign, a dot and a 2-4 characters long TLD.
You can use the above regular expression to validate a given email address as shown below:
function validate_email (email) {
   /* Define the recommended regular expression. */
   var emailExp = new RegExp(/^\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b$/i);
   /* Test the email given against the expression and return the result. */
   return emailExp.test(email);
}
jQuery Validator:
jQuery Validator doesn't support the use of regular expressions and instead uses the default HTML5 email regular expression internally, so you must first create a new method for the validator that does that:
$.validator.addMethod(
    /* The value you can use inside the email object in the validator. */
    "regex",
    /* The function that tests a given string against a given regEx. */
    function(value, element, regexp)  {
        /* Check if the value is truthy (avoid null.constructor) & if it's not a RegEx. (Edited: regex --> regexp)*/
        if (regexp && regexp.constructor != RegExp) {
           /* Create a new regular expression using the regex argument. */
           regexp = new RegExp(regexp);
        }
        /* Check whether the argument is global and, if so set its last index to 0. */
        else if (regexp.global) regexp.lastIndex = 0;
        /* Return whether the element is optional or the result of the validation. */
        return this.optional(element) || regexp.test(value);
    }
);
Now that a method supporting validation against a regular expression was created for the validator, you can use the jQuery.validate as follows:
$('#element_id').validate({
    email: {
        required: true,
        email: true,
        regex: /^\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b$/i
    }
});
To filter an email address and only accept a format like name@domain.tld use this regular expression:
var emailExp = new RegExp(/\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b/i);
This regular expression filters out any "junk" that may be entered and requires that an @-sign, a dot and a 2-4 characters long TLD be present. If a substring of the given email address matches it the substring is returned, otherwise false.
You can use the above regular expression to filter a given email address as shown below:
function filter_email (email) {
   var
      /* Define the recommended regular expression. */
      emailExp = new RegExp(/\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b/i),
      /* Use 'match' to filter the email address given and cache the result. */
      filtered = email.match(emailExp);
   /* Return the filtered value or false. */
   return filtered ? filtered[0] : false;
}
When answering the OP's question more than a year ago, I mistook his intention for email validation as an attempt to filter a given string keeping only a substring of it that is an email address.
This answer considers addresses lacking a TLD invalid even though they are perfectly valid in the real world as per OP's request.
 
    
     
    
    try this
function isEmail(email) {
  var regex = /^([a-zA-Z0-9_.+-])+\@(([a-zA-Z0-9-])+\.)+([a-zA-Z0-9]{2,4})+$/;
  return regex.test(email);
}
 
    
    $(function() {
// Setup form validation on the #register-form element
$("#login-form").validate({
    // Specify the validation rules
    rules: {
        email: {
            required: true,
            email: true
        }
    },
    // Specify the validation error messages
    messages: {         
        email: "Please enter a valid email address"
    },
    submitHandler: function(form) {
        form.submit();
    }
});   });
i hope it will be helpful
 
    
    var re=new RegExp();
    re = /^(([^<>()\[\]\.,;:\s@\"]+(\.[^<>()\[\]\.,;:\s@\"]+)*)|(\".+\"))@(([^<>()[\]\.,;:\s@\"]+\.)+[^<>()[\]\.,;:\s@\"]{2,})$/i;
if(re.test(Email_Value)){
   alert("valid email");
}
