Regex for an email address doesn't work

后端 未结 8 2081
隐瞒了意图╮
隐瞒了意图╮ 2021-02-04 22:32

I\'m trying to check if some email address is correct with the following code :

NSPredicate *regexMail = [NSPredicate predicateWithFormat:@\"SELF MATCHES \'.*@.*         


        
8条回答
  •  醉梦人生
    2021-02-04 23:15

    This page has a good explanation of using regular expressions to validate email, as well as some regexes:

    http://www.regular-expressions.info/email.html

    Their expression:

    [a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?
    

    Seems to be the best tradeoff between thoroughness and correctness.

提交回复
热议问题