0

I figured a way to do validation. I found that inside models, i need to add these lines

validates_presence_of :name validates_uniqueness_of :name

What i'm trying to achieve is for example, i don't want the user to add :;!@#$%^&*() [or special characters] in my text inputs. Need some inputs on this.

1
  • 1
    Use the :format as described in the docs Commented Jan 16, 2013 at 17:59

1 Answer 1

4

You can use format_of:

validates_format_of :name, :with => /\A[a-zA-Z]+([a-zA-Z]|\d)*\Z/

Or create your own validation:

validates :name,
   :presence   => true,
   :format     => { :with => regex } # Here you can set a 'regex'
Sign up to request clarification or add additional context in comments.

1 Comment

That was totally quick. Thanks a ton.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.