1

I have used regular form for validating first name field. It allow only letters but not allowing spaces. I have used like

validates :first_name,    presence: true,
                         format: { with:/\A[a-z_]+\Z/, message: 'Only letters are allowed' }

If I give abc asd in first name field. It shows message like "only letters allowed"

4
  • "abc asd" contains spaces Commented Oct 30, 2013 at 11:24
  • 1
    what do you want the regex to validate? Commented Oct 30, 2013 at 11:24
  • Please give us sample input and sample output. Commented Oct 30, 2013 at 11:25
  • obviously, s?he wants to add spaces to the allowed list which is quite ironic since it's damn easy: just add a space in the character class. Commented Oct 30, 2013 at 11:38

1 Answer 1

1

Spaces aren't letters.

Do you want to allow spaces in the first name field? If so you need to add a space to your list of things to test: \A[a-z_ ]+\Z

Also.. your users won't be able to use capitals for their name. If you want to allow capital letters use \A[a-zA-Z_ ]+\Z

Hope this helps.

Sign up to request clarification or add additional context in comments.

Comments

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.