rails - 用于电子邮件验证的正则表达式 [英] rails - REGEX for email validation

查看:43
本文介绍了rails - 用于电子邮件验证的正则表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一个正则表达式来验证电子邮件以了解它是否有效..我有以下内容:

I'm looking for a regex to validate an email to learn if it's valid or not.. I have the following:

def is_a_valid_email?(email)
    email_regex = %r{
      ^ # Start of string
      [0-9a-z] # First character
      [0-9a-z.+]+ # Middle characters
      [0-9a-z] # Last character
      @ # Separating @ character
      [0-9a-z] # Domain name begin
      [0-9a-z.-]+ # Domain name middle
      [0-9a-z] # Domain name end
      $ # End of string
    }xi # Case insensitive

    (email =~ email_regex)
end

上面的问题是 XXX_XXX@Xxx.com 在应该有效时没有返回.对更好的正则表达式有什么想法或建议吗?

Problem with the above is XXX_XXX@Xxx.com does not return as valid when it should be. Any thoughts or suggestions for a better regex?

谢谢

推荐答案

我对此的看法(见上面的评论和链接):

My shot at this (see comment and link above):

^.+@.+$

这篇关于rails - 用于电子邮件验证的正则表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆