You still want to use model checks.
Something like this is possible:
class User validates :username, :format => { :with => /your regex/ }, :uniqueness => true end # then in some controller action or rack app def test_username user = User.new(:username => params[:username]) # Call user.valid? to trigger the validations, then test to see if there are # any on username, which is all you're concerned about here. # # If there are errors, they'd be returned so you can use them in the view, # if not, just return success or something. # if !user.valid? && user.errors[:username].any? render :json => { :success => false, :errors => user.errors[:username] } else render :json => { :success => true } end end
source share