I would like to check a field with a regex, and also let it be empty (accept an empty string). So far, the only thing I have managed to do is to write a regular expression that allows an empty string, for example:
validates :field, format: { with: /\A([az]+|)\z/i }
Now this cannot be the right way - it seems like an ugly hack. I would like to know if there is another (correct) approach?
aL3xa source share