Rails validates with regex is not working? -


simple regex not working.. example first_name = "a11" works fine. why isn't format regex validating properly?

  validates :first_name, presence: { message:  "name cannot blank." },                          format: { with: /[a-z]/i, message:  "name must contain letters." },                          length: { minimum: 2, message:  "name must @ least 2 letters." } 

because matches regex.

you have specify begin , end of string, , add * or match 1 char.

format: { with: /\a[a-z]*\z/i, message:  "name must contain letters." }, 

also note don't use ^ , $, in ruby, ^ , $ matches begin , end of line, not string, broken on multiline strings.


Comments

Popular posts from this blog

google api - Incomplete response from Gmail API threads.list -

Installing Android SQLite Asset Helper -

Qt Creator - Searching files with Locator including folder -