Super simple email validation with javascript

前端 未结 8 747
爱一瞬间的悲伤
爱一瞬间的悲伤 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.

提交回复
热议问题