Super simple email validation with javascript

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

    The least possible greedy validation you an do is with this RegExp /^.+@.+\..+$/
    It will only ensure that the address fits within the most basic requirements you mentioned: a character before the @ and something before and after the dot in the domain part. Validating more than that will probably be wrong (you always have the chance of blacklisting a valid email).

    use it like this:

    var is_valid_email = function(email) { return /^.+@.+\..+$/.test(email); }
    

提交回复
热议问题