Search code examples
jqueryruby-on-railsvalidationclient-side-validation

How to perform client side validation using jquery in rails 3 forms


I want to perform client side validation using jquery in rails 3 forms

for the following form

the fields may be email,mobile number,etc

<%= form_for(@user) do |f| %>
<div class="field">
  <%= f.label :Name %><br />
  <%= f.text_field :name %>
</div>

<div class="field">
  <%= f.label :Contact_number %><br />
  <%= f.text_field :contact_number %>
</div>
<div class="field">
  <%= f.label :Licence_type %><br />
  <%= f.text_field :licence_type %>
</div>

<div class="actions">
 <%= f.submit %>
</div>
<% end %>

please help me for the above validations

or any other client-side validation you may suggest for me


Solution

  • The client_side_validations gem should help with your issue. It will detect standard rails validators, and apply them in javascript, and allows you to add your own custom validators when necessary.

    Disclaimer: I work with bcardarella