Email validation using regular expression in PHP

后端 未结 11 1552
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-11-30 01:38

I am pretty much new with regular expression. I am developing a project in PHP and i need to validate email address. After searching in this site and google i found the fol

11条回答
  •  一个人的身影
    2020-11-30 02:37

    Email validation regex (domain with sub domains)

    ^((([a-z0-9]+[\-]{0,1})+[a-z0-9]+?\.)+[a-z0-9][a-z0-9|\-]+[a-z0-9])@([a-z0-9]+[\-|\.]{0,1}[a-z0-9]+)+(.[a-z0-9]{2,})+$
    

    Sample tests https://regex101.com/r/w5VBdf/20

    Domain with sub domains

    ^([a-z0-9]+[\.|\-]{0,1}[a-z0-9](.[a-z0-9]{2,})+)$
    

    https://regex101.com/r/4Un8Tz/2

    Email username

    ^([a-z0-9]+[\.|\-]{0,1}[a-z0-9]{1,})+@$
    

    https://regex101.com/r/4Un8Tz/6

提交回复
热议问题