# Validates\_format\_of problem with REGEX

**URL:** <https://www.ruby-forum.com/t/validates-format-of-problem-with-regex/112020>\
**Category:** Rails\
**Created:** [August 14, 2007, 11:24am UTC](https://www.ruby-forum.com/t/validates-format-of-problem-with-regex/112020 "2007-08-14T11:24:17Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![le\_colibri](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/ccd318/32.png) [@le\_colibri](https://www.ruby-forum.com/u/le_colibri)\
**Post date:** [August 14, 2007, 11:24am UTC](https://www.ruby-forum.com/t/validates-format-of-problem-with-regex/112020/1 "2007-08-14T11:24:17Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![le\_colibri](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/ccd318/32.png) [@le\_colibri](https://www.ruby-forum.com/u/le_colibri)\
**Post date:** [August 14, 2007, 1:25pm UTC](https://www.ruby-forum.com/t/validates-format-of-problem-with-regex/112020/2 "2007-08-14T13:25:44Z")

</div>

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.

–  
We develop, watch us RoR, in numbers too big to ignore.

---

<div class="post-metadata">

**Author:** ![le\_colibri](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/ccd318/32.png) [@le\_colibri](https://www.ruby-forum.com/u/le_colibri)\
**Post date:** [August 14, 2007, 3:38pm UTC](https://www.ruby-forum.com/t/validates-format-of-problem-with-regex/112020/3 "2007-08-14T15:38:13Z")

</div>

Mark Reginald J. wrote:

> > 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.
