Skip to content

Instantly share code, notes, and snippets.

@raddrick
Created January 17, 2013 16:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save raddrick/4557351 to your computer and use it in GitHub Desktop.
Save raddrick/4557351 to your computer and use it in GitHub Desktop.
field_type :optional_name_check do
field :self do
type :text_field, :minlength=>0
end
validates :logic=>lambda{ |field|
if (get_value.length==1) || ((get_value.split(/(.)\1\1/).join != get_value) || (get_value.split(/[@#\$%&*_;:"+=.,<>?\\\}\{\^\(\)\]\[]/).join != get_value )) && (get_value.length >1)
errors.add(field_name, "Only alphabetic, not 3 consecutive identical, longer than 1 character.")
end
} , :allow_blank=>true
end
field_type :name_check do
field :self do
type :text_field
end
# validates_length :is => 2, :allow_blank => true
validates :logic=>lambda{ |field|
#if (get_value.split(/(.)\1\1/).join != get_value) || (get_value.to_s.length<2) || (get_value.split(/[@#\$%&*_;:"+=.,<>?\\\}\{\^\(\)\]\[]/).join != get_value )
if (get_value.length==1) || ((get_value.split(/(.)\1\1/).join != get_value) || (get_value.split(/[@#\$%&*_;:"+=.,<>?\\\}\{\^\(\)\]\[]/).join != get_value )) && (get_value.length >1)
errors.add(field_name, "Only alphabetic, not 3 consecutive identical, longer than 1 character")
end
}
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment