Super simple email validation with javascript

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

    Based on Ian Christian Myers reply before this, this answer adds + sign and extend to tld with more than 4 chars

    function validateEmail(email) {
        const regex = /^[a-zA-Z0-9.+_-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,15}$/;
        return regex.test(email);
    }
    

提交回复
热议问题