i have form include number fields
<%= f.number_field :contribution_to_sales, class: 'form-control',:pattern=>["\d+"] %>
it allows 2.0 want should not allow 2.0 . how that?
you missing anchors on regular expression causes "2" in "2.0" matched (on browsers). regex use is:
<%= ... pattern: "^\d+$" %>
you should doing validation on model well, html5 pattern attribute may not obeyed browsers. add:
class yourmodel < activerecord::base validates :contribution_to_sales, numericality: { only_integer: true } ... end
Comments
Post a Comment