How can I allow only gmail.com as domain in my email field validating using jquery-validation plugin ?
$(\"#myForm\").validate({
rules: {
myemail: {
You can accept gmail like this below, notice I added in for it to ignore .org and .net as well you can keep tweaking your regex to exactly how you want it.
\w*\@(?!org)(?!net)[g][m][a][i][l]
Edit based on Sparky's : CASE -- Uppercase and 3 letter email name @gmail.com
$(document).ready(function () {
jQuery.validator.addMethod('gmail', function (value, element) {
return this.optional(element) || /^[a-z0-9](\.?[a-z0-9]){3,}@[Gg][Mm][Aa][Ii][Ll]\.com$/i.test(value);
}, "not a valid Gmail email address");
$('#myform').validate({
rules: {
field1: {
required: true,
gmail: true
}
},
submitHandler: function (form) { // for demo
alert('valid form');
return false;
}
});
});