validates_format_of problem with REGEX

Dear Railers,

I'm having trouble with the following code:

validates_format_of :class, :with => /^PL[DTV]\d{1}[a-z]{1}/, :message => 'blah blah:'

The class should start with PL and be followed by D, T or V, followed by 1 digit and one letter.

Now I tried things like PLV2a, PLT1c and so on; none will validate...

I tried the REGEX it in BBedit with GREP searching and the pattern ^PL[DTV]\d{1}[a-z]{1} finds all of them without problems...

Any clue...

Kind regards,

Robert.

le colibri wrote:

validates_format_of :class, :with => /^PL[DTV]\d{1}[a-z]{1}/, :message => 'blah blah:'

The class should start with PL and be followed by D, T or V, followed by 1 digit and one letter.

Now I tried things like PLV2a, PLT1c and so on; none will validate...

I tried the REGEX it in BBedit with GREP searching and the pattern ^PL[DTV]\d{1}[a-z]{1} finds all of them without problems...

Rename your attribute to avoid clashing with the built-in class method.

Mark Reginald James wrote:

le colibri wrote:

> validates_format_of :class, :with => /^PL[DTV]\d{1}[a-z]{1}/, :message > => 'blah blah:' > > The class should start with PL and be followed by D, T or V, followed > by 1 digit and one letter. > > Now I tried things like PLV2a, PLT1c and so on; none will validate... > > I tried the REGEX it in BBedit with GREP searching and the pattern > ^PL[DTV]\d{1}[a-z]{1} finds all of them without problems...

Rename your attribute to avoid clashing with the built-in class method.

Thanks Mark, it works like a charm now.

Robert.