I have a validation that checks the format of a url using regex. I was wondering if it’s possible to put the regex inside of a method:
validates_format_of :table_name :with => /^(http|https):\/\/[a-z0-9]+([_-.]{1}[a-z0-9]+).[a-z]{2,5}(:[0-9]{1,5})?(\/.)?$/ix
How do I put that regex in a method and use it with the validation?
It’ll work with any class method, or variable/constant that’s already defined. But why don’t you create a new validator?
Then: