create custom validation

hi, i created a validation to prevent users to write text uppercase in
my fields, i have writing the code on my class model like this:

Try this

def validates_on_yours_method_name
size_letters = field.scan(/\w/).size
size_invalid = field.scan(/[A-Z]/).size
if size_invalid > 0
if (size_letters / size_invalid) < 4 and size_letters > 10
errors.add( field,
I18n.t('activerecord.errors.

messages.uppercase’))

    write_attribute(field, field.downcase)

  end

end

end

Do you really need to "prevent" them, or can you just downcase it
and be done? In any case, wouldn't the easiest check be something
like

  unless ( field.downcase == field ) errors.add( ... )

?

i have resolved with this:

  #prevent users to write text uppercase, and reset field text to
lowercase
  validates_each :title, :description do |model, attr, value|
    size_letters = value.scan(/\w/).size
    size_invalid = value.scan(/[A-Z]/).size
    if size_invalid > 0
      if (size_letters / size_invalid) < 4 and size_letters > 10
        model.errors.add( attr,
I18n.t('activerecord.errors.messages.uppercase'))
        model.write_attribute(attr, value.downcase)
      end
    end
  end

for Hassan Schroeder: i want the user write in uppercae only certain
letters( itials of names, letter after points, etc..). with my solution
i concur the user to write in the text the 25% of letters uppercase.

thanks to all.