Ruby on Rails 3,多个域的电子邮件验证?
嘿伙计们,我在这里遇到了一个问题。有没有办法拥有两种可接受的电子邮件格式?
你看,我正在构建的网站需要让用户注册到某个域,并且学生和工作人员共享不同的域。例如:[电子邮件受保护] 和 [电子邮件受保护]。我希望导师和学生能够注册。到目前为止我已经尝试过了:
EMAIL_STAFF_REGEX = /\A[\w+\-.][email protected]/i
email_regex = /\A[\w+\-.][email protected]/i
validates :email, :presence => true,
:format => { :with => email_regex,
:with => EMAIL_STAFF_REGEX},}
我将非常感谢任何帮助。
hey guys, I'm running into a issue here. Is there a way to have TWO acceptable email formats?
You see, the site I'm building needs to have users register with a certain domain, and the student, and staff share different domains. For Example: [email protected], and [email protected]. I want tutors, and students to be able to sign up. I've tried this so far:
EMAIL_STAFF_REGEX = /\A[\w+\-.][email protected]/i
email_regex = /\A[\w+\-.][email protected]/i
validates :email, :presence => true,
:format => { :with => email_regex,
:with => EMAIL_STAFF_REGEX},}
I would greatly appreciate any help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我假设您将正则表达式分开,因为您希望稍后能够使用正则表达式来判断他们是导师还是学生。
尝试
我建议将导师列设置为实际字段,以便您可以对其进行查询,然后使用验证来确保电子邮件匹配相同的格式。
I'm assuming you are splitting the regexp's out because you want to be able to use the regexp later to tell if they are a tutor or student.
Try
I would recommend making the tutor column an actual field so you can do queries on it and then use validations to make sure that the email matches the same format.