How do you create a simple, custom rule using the jQuery Validate plugin (using addMethod
) that doesn't use a regex?
For example, what function would create a rule that validates only if at least one of a group of checkboxes is checked?
How do you create a simple, custom rule using the jQuery Validate plugin (using addMethod
) that doesn't use a regex?
For example, what function would create a rule that validates only if at least one of a group of checkboxes is checked?
For this case: user signup form, user must choose a username that is not taken.
This means we have to create a customized validation rule, which will send async http request with remote server.
<input name="user_name" type="text" >
class Interface::UsersController < ActionController::Base def is_username_valid render :text => !User.exists?(:user_name => params[:user_name]) end end
it works perfectly.
Thanks, it worked!
Here's the final code:
You can create a simple rule by doing something like this:
And then applying this like so:
Just change the contents of the 'addMethod' to validate your checkboxes.
You can add a custom rule like this:
And use it like this:
Hope this helps