I have a Message.uuid field which I want to add validations for which include:
Supported:
- A-Z, a-z, 0-9
- dashes in the middle but never starting or ending in a dash.
- At least 5, no more than 500 characters
What is the best way in rails to write a model validation for these rules?
Thanks
UPDATE:
validates :uuid,
:length => { :within => 5..500 },
:format => { :with => /[A-Za-z\d][-A-Za-z\d]{3,498}[A-Za-z\d]/ }
With a valid UUID this is failing
^and$, or something like"@%#@#$AAAAA@#%@#$"will pass.formatvalidator; you currently attempting to validate length twice, and a UUID likeAAAwill cause two errors: one about the length, and one about the format. You probably only want it to cause alengtherror.