Hi all,
I have the following line in my model:
validates_format_of :postal_code, :with => /\d{4}\s*[a-zA-Z]{2}/, :on =>
:create
However this still does allow me to create a postal code such as:
5444 ABC
which is incorrect, because it should only be allowed if two characters
are
supplied at the end.
In java the same regex is working, what am I doing wrong here?
Regards,
Harm
On 20 October 2006 15:17, Harm de Laat wrote:
5444 ABC
which is incorrect, because it should only be allowed if two characters are
supplied at the end.
In java the same regex is working, what am I doing wrong here?
Add ^ at the beginning and $ - at the end:
validates_format_of :postal_code, :with => /^\d{4}\s*[a-zA-Z]{2}$/, :on
=> :create
On Oct 20, 2006, at 4:17 AM, Harm de Laat wrote:
I have the following line in my model:
validates_format_of :postal_code, :with => /\d{4}\s*[a-zA-Z]
{2}/, :on => :create
However this still does allow me to create a postal code such as:
5444 ABC
Your expression looks fine, but you can’t expect all parsers to
behave identically. You might try doing [a-zA-Z][a-zA-Z].
Jose
…
Jose Hales-Garcia
UCLA Department of Statistics
[email protected]