Yes you can do it with Model validation
along with a Regular Expression
. So if you are only allowing the given values i.e., '00,00', '00:00,00', '0,00' , you can do:
class ModelName < ActiveRecord::Base
validates_format_of :field_name, :with => /((\A[0]{2}(\,|\:)[0]{2}((\,)[0]{2})*\Z)|(\A[0]{1}(\,)[0]{2}\Z))/i, :message => " is Invalid"
end
Check it here http://rubular.com/r/7ZGo0ktlSe
Update as per the comment from Xeen:
If you allow all the digits [0-9], the you can go for the answer below:
class ModelName < ActiveRecord::Base
validates_format_of :field_name, :with => /((\A\d{2}(\,|\:)\d{2}((\,)\d{2})*\Z)|(\A\d{1}(\,)\d{2}\Z))/i, :message => " is Invalid"
end
Check http://rubular.com/r/c2Q5K3armn.
Hope it helps :)