I need to validate input evidence number as per following formats in my model.
XXX-###
XXX-####
XXX-#####
XXX-######
XXXX-#####
XXXX are alphabets and #### are numeric digits
I have following in my model code.
validates_format_of :evidence_number, :with=> /[A-Z a-z]{3}-\d{3,6}/
It only works for digits less than 3 ie it works for XXX-12 but does not work for digits more than 6 i.e. it does not work for XXX-1234567
Try adding the
^starts and$ends with.Use
mu is too short‘s answer though.