airi
airi

Reputation: 585

How to make jQuery domain validation for email?

I have an input for email and have validation for a@a but not have validation for .com.nz , .com, .org .sg

How to validate domain in email using jquery?

<input class="form-control" type="text" id="username" maxlength="100" name="username" required="required">

Upvotes: 1

Views: 100

Answers (1)

Asok Kumar
Asok Kumar

Reputation: 11

Use custom validation rule

$.validator.addMethod("customemail", 
    function(value, element) {
        return /^([a-zA-Z0-9_.-+])+\@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/.test(value);
    }, 
    "Sorry, I've enabled very strict email validation"
);

Upvotes: 1

Related Questions