【发布时间】:2015-03-08 16:47:32
【问题描述】:
我有简单的注册表单。我已经设置了多个验证。除了 电子邮件格式验证。
在模型中:
validates :name,:region, :age, :height,:phone_number,:weight, :email,
:description,
:presence => {:message => "empty value found"}
validates_format_of :email, :with => /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i
查看:
<%= f.email_field :email,:placeholder=> "E-pasts *", :validate => true%>
脚本:
function validate() {
judge.validate(document.getElementById('advertisement_email'), {
valid: function(element) {
element.style.border = '1px solid green';
},
invalid: function(element, messages) {
element.style.border = '1px solid red';
alert(messages.join(','));
}
});
}
从提交按钮触发验证。
<div class="clickable8 ">
<%= link_to "PIEVIENOT", "#", :onclick => "validate()" %>
<span style="padding-left:132px;">PIEVIENOT</span>
</div>
问题:
1) 在 Chrome 中验证通过,即使电子邮件字段中没有任何内容。
2) 在 Firefox 中,验证与我在该字段中写作的同时工作。
它通过有效的电子邮件并通过无效的电子邮件失败。根据我的需要。
问题:如何在两个浏览器中使用该点击按钮触发验证?
提前致谢。
【问题讨论】:
标签: jquery ruby-on-rails ruby validation