user1199657
user1199657

Reputation:

Email Validation in Javascript based upon domain look up

I know this question has been posted many times. But still i would like to inquire a little more. I have used a function

function validateEmail(elementValue){  
       var emailPattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,3}$/;  
         return emailPattern.test(elementValue);  
    }   

It works fine. But my problem is that it allows [email protected] as a valid email. So i want to check the domain also like checkdnsrr() does in php. Can i do it in javascript? I want to check for valid domain also.

Upvotes: 1

Views: 1245

Answers (3)

Cassius Maradona
Cassius Maradona

Reputation: 1

On the same code that you have Provided

function validateEmail(elementValue){  
   var emailPattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,3}$/;  
     return emailPattern.test(elementValue);  
} 

Change it in this manner and it will validate [email protected] Checking that the Domain can not be @123.com

function validateEmail(elementValue){  
   var emailPattern = /^[a-zA-Z0-9._-]+@[a-zA-Z-]+\.[a-zA-Z]{2,3}$/;  
     return emailPattern.test(elementValue);  
}  

Upvotes: 0

provokoe
provokoe

Reputation: 178

Why don't you do it in php? That will be much easier than making an ajax call.

Upvotes: 0

Florian Margaine
Florian Margaine

Reputation: 60707

It looks like there is no other solution than using AJAX to do this.

You do a request on your server with JS, the server checks the DNS using checkdnsrr(), and it responds with whatever you want, it will allow your JS to handle the validation depending on this.

Upvotes: 1

Related Questions