I want to validate the entered email id domain using jQuery. For security reason we restrict the email id to only 2 email domain like company1.com and **company2.co, **.
So, if the user enters [email protected] then we need to display the error message enter a valid email address.
The user is allowed to enter only like [email protected] or [email protected].
I am using the below code but it is not working:
jQuery.validator.addMethod("domain", function(
value, element) {
var val = value.substring(value.indexOf('@')+1, value.length);
return this.optional(element) || /'company1.com'/.test(val) || /'company2.com'/.test(val);
}, 'Enter a valid email address');
In rules I am adding domain: true
could you please tell me where I missed?