【发布时间】:2014-03-12 13:40:51
【问题描述】:
我有用于电子邮件验证以下规则的正则表达式
电子邮件地址的本地部分可以使用以下任何 ASCII 字符:
Uppercase and lowercase English letters (a-z, A-Z)
Digits 0 to 9
Characters ! # $ % & ' * + - / = ? ^ _ ` { | } ~
Character . (dot, period, full stop) provided that it is not the first or last character, and provided also that it does not appear two or more times consecutively.
/^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/i
它在 Javascript 中工作,但在 Ruby http://rubular.com/ 中它给出错误“字符类过早结束”。
我该如何解决这个问题?
【问题讨论】:
标签: ruby-on-rails ruby regex ruby-on-rails-3