在 Ruby 中验证电子邮件地址的最佳/简单方法是什么? [英] What is the best/easy way to validate an email address in Ruby?

查看:38
本文介绍了在 Ruby 中验证电子邮件地址的最佳/简单方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 ruby​​ 中(在服务器端)验证电子邮件地址的最佳/简单方法是什么?

What is the best/easy way to validate an email address in ruby (on the server side)?

推荐答案

您可以查看它是否与此 Rails 验证器中使用的正则表达式匹配:

You could look whether or not it matches a regexp like the one used in this Rails validator:

validates_format_of :email,:with => /\A[^@\s]+@([^@\s]+\.)+[^@\s]+\z/

但如果您使用 Devise,只需执行以下操作:

But if you use Devise, simply do:

validates_format_of :email,:with => Devise::email_regexp

来源:http://lindsaar.net/2008/4/14/tip-4-detecting-a-valid-email-address

编辑 1:

有用的测试网站:http://www.rubular.com/

这篇关于在 Ruby 中验证电子邮件地址的最佳/简单方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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