Javascript Validation Code to Block Free Emails (Gmail, Yahoo) & Allow Business Emails in Forms

Javascript Validation Code to Block Free Emails (Gmail, Yahoo) & Allow Business Emails in Forms

Since really long I was trying to get this done. I found the javascript code which can validate email fields in any contact form for only allowing business email ids & block free mail domains like gmail, yahoo, live, aol, etc. Recently I wrote on same lines but for contact form 7 plugin in WordPress. This procedure will now work on any platform, you will just need to use proper id selectors in javascript. So, here is the script.

<script type="text/javascript">
$(document).ready(function(e){
 $('#btnSubmit').click(function(){ 
 var email = $('#Email').val();
 var reg = /^([\w-\.]+@(?!gmail.com)(?!yahoo.com)(?!hotmail.com)(?!yahoo.co.in)(?!aol.com)(?!abc.com)(?!xyz.com)(?!pqr.com)(?!rediffmail.com)(?!live.com)(?!outlook.com)(?!me.com)(?!msn.com)(?!ymail.com)([\w-]+\.)+[\w-]{2,4})?$/;
  if (reg.test(email)){
 return 0;
 }
 else{
 alert('Please Enter Business Email Address');
 return false;
 }
 });
});
</script> 

For this work properly you need to have HTML code around below


<form id="yourid" action="youraction" method="POST/GET">
<input type="text" name="email" id="Email">
<input type="submit" id="btnSubmit" name="download_submit" value="Submit">
</form>

2 Comments


Leave a Reply

Your email address will not be published. Required fields are marked *

Show Buttons
Hide Buttons
%d bloggers like this: