custom error message for validates_length_of :maximum and :minimum on ruby on rails

user3678471

I want to write a custom error message for :minimum and other for :maximum

I have the following the code line

validates_length_of :user_name, :minimum=>5,:maximum=>30

  ej if the length of :user_name is < 5 "The user_name must to have 5 characters as minimum"
  ej if the length of :user_name is > 30 "The user_name must to have 30 characters as maximum" 
tadman

The newer notation for this is:

validates :user_name,
  length: { 
    minimum: 5,
    maximum: 30,
    too_short: "The user name must have at least %{count} characters.",
    too_long: "The user name must have no more than %{count} characters."
  }

More examples are listed in the documentation.

The old validates_length_of type methods are left in there for legacy support but should probably be avoided in new code.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Rails: validates_length_of

From Dev

limited minimum and maximum length to email with regex but error

From Dev

Rails validates doesn't accept custom message

From Dev

ruby on rails validation does not show the error message

From Dev

Signup page error message in ruby on rails

From Dev

Rails custom validation error message not working

From Dev

Rails 4.2 ActionController:BadRequest custom error message

From Dev

Display error message if user entered less than minimum length

From Dev

validates_length_of with a variable

From Dev

validates_length_of with a variable

From Dev

Ruby on Rails: How to customise error message for MailForm when field is blank

From Dev

iOS Progress bar custom maximum and minimum values

From Dev

Rails validates_associated with model's error message

From Dev

Rails 4: remove attribute name from error message in custom validator

From Dev

Custom error message for invalid confirmation token in Devise for Rails

From Dev

Custom string in rails 4 active records error message

From Dev

Rails 4, Adding custom layout, got error message

From Dev

Custom scaffold in ruby on rails

From Dev

Custom Search in Ruby on Rails

From Dev

NumericUpDown error: Value should be between minimum and maximum

From Dev

What is the maximum SMS message length?

From Dev

Chrome extension maximum message length

From Dev

JWPLAYER custom error message

From Dev

Custom Error Message MVC

From Dev

Raise custom error message for

From Dev

Rendering error message in rails

From Dev

Rails Showing Error Message

From Dev

Find path with minimum cost and maximum length given a maximum cost

From Dev

How to set a custom minimum and maximum date selection day in "wdullaer materialdatetimepicker"

Related Related

  1. 1

    Rails: validates_length_of

  2. 2

    limited minimum and maximum length to email with regex but error

  3. 3

    Rails validates doesn't accept custom message

  4. 4

    ruby on rails validation does not show the error message

  5. 5

    Signup page error message in ruby on rails

  6. 6

    Rails custom validation error message not working

  7. 7

    Rails 4.2 ActionController:BadRequest custom error message

  8. 8

    Display error message if user entered less than minimum length

  9. 9

    validates_length_of with a variable

  10. 10

    validates_length_of with a variable

  11. 11

    Ruby on Rails: How to customise error message for MailForm when field is blank

  12. 12

    iOS Progress bar custom maximum and minimum values

  13. 13

    Rails validates_associated with model's error message

  14. 14

    Rails 4: remove attribute name from error message in custom validator

  15. 15

    Custom error message for invalid confirmation token in Devise for Rails

  16. 16

    Custom string in rails 4 active records error message

  17. 17

    Rails 4, Adding custom layout, got error message

  18. 18

    Custom scaffold in ruby on rails

  19. 19

    Custom Search in Ruby on Rails

  20. 20

    NumericUpDown error: Value should be between minimum and maximum

  21. 21

    What is the maximum SMS message length?

  22. 22

    Chrome extension maximum message length

  23. 23

    JWPLAYER custom error message

  24. 24

    Custom Error Message MVC

  25. 25

    Raise custom error message for

  26. 26

    Rendering error message in rails

  27. 27

    Rails Showing Error Message

  28. 28

    Find path with minimum cost and maximum length given a maximum cost

  29. 29

    How to set a custom minimum and maximum date selection day in "wdullaer materialdatetimepicker"

HotTag

Archive