D
Dara Sanderson
Hello,
I hope someone can help me or at least confirm that I'm not going
insane.
I have a model in which I'm trying to validate information before it
saves.
One particular field is for and expiration date. The code in my model
to do the validation looks like this:
validates_format_of :expiration,
:with => %r{^[\d]{4,4}$},
:message => "must be formatted (mmyy)"
The problem is if someone enter a date that starts with a zero like
"0309" The validation somehow just doesn't "see" the leading zero and
keeps returning an error as though the user isn't submitting it
properly. I did verify that the controller is definetly sending all
four digits in the post.
I tried different combinations like: r{^(0|1)[\d]{3}$} but no matter
what I did the zero was ignored. I finally had to change it to look for
3 or 4 digits just to make it work but that of course isn't proper
validation as my submissions must have 4 digits.
Can anyone help me? Am I going crazy here?
Thanks,
Dara
I hope someone can help me or at least confirm that I'm not going
insane.
I have a model in which I'm trying to validate information before it
saves.
One particular field is for and expiration date. The code in my model
to do the validation looks like this:
validates_format_of :expiration,
:with => %r{^[\d]{4,4}$},
:message => "must be formatted (mmyy)"
The problem is if someone enter a date that starts with a zero like
"0309" The validation somehow just doesn't "see" the leading zero and
keeps returning an error as though the user isn't submitting it
properly. I did verify that the controller is definetly sending all
four digits in the post.
I tried different combinations like: r{^(0|1)[\d]{3}$} but no matter
what I did the zero was ignored. I finally had to change it to look for
3 or 4 digits just to make it work but that of course isn't proper
validation as my submissions must have 4 digits.
Can anyone help me? Am I going crazy here?
Thanks,
Dara