I’ve got a form which accepts a “price” field and I’m attempting to
validate it and allow some flexibility in the way the user enters it.
It’s a numeric field but I want the user to be able to enter dollar
signs and commas naturally in the data entry.
I’m trying to understand how to use validates_format_of, and I’m not
sure what I’m missing. I’m a beginner at regular expressions but I’ve
been researching it.
I tried an extremely simple case:
validates_format_of :price, :with => /^\d$/
If I understand correctly, this validation should only succeed for a
single digit character and nothing else? I added this to my model and
so far it passes everything–numbers, characters, whitespace, etc.
What am I doing wrong? I figure I’ll get this simplest case working and
move on from there.