Super simple email validation with javascript

前端 未结 8 727
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-14 00:32

I\'m making a really simple email validation script that basically just checks the following

  1. that the email isn\'t blank
  2. the the email contains an @ s
相关标签:
8条回答
  • 2020-12-14 01:19

    Try:

    function valid_email(email) {
       return email.match(/^([\w\!\#$\%\&\'\*\+\-\/\=\?\^\`{\|\}\~]+\.)*[\w\!\#$\%\&\'\*\+\-\/\=\?\^\`{\|\}\~]+@((((([a-z0-9]{1}[a-z0-9\-]{0,62}[a-z0-9]{1})|[a-z])\.)+[a-z]{2,6})|(\d{1,3}\.){3}\d{1,3}(\:\d{1,5})?)$/i);
    }
    

    That is the best available email validation regex, according to this article. I recommend using this, unless your goal is something really simple but not fully compatible.

    0 讨论(0)
  • 2020-12-14 01:25

    If you want to check only for Business Emails then try this :

    <script type="text/javascript">
    $(document).ready(function(e){
         $('#sendReq').click(function(){ 
         var email = $('#emailAddress').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>
    
    0 讨论(0)
提交回复
热议问题