Hi
… somebody around who is easy with Reg. Exressions.
For me a nightmare.
I have to Validate this format: 0-0000 0000 and/or 0-0000 0000/0 and/or 0-0000 0000/00
Would be a great help…
I have got: (^\d-\d{4} \d{4}(/\d{2})?$)|(^I\d{8}$)|(^$)
tried:
validates :project_number, :format => { :with => /(^\d-\d{4} \d{4}(/\d{2})?$)|(^I\d{8}$)|(^$)/, :message => “Message”}
But that seems to be not valid.
Thanks
Hi
.. somebody around who is easy with Reg. Exressions.
For me a nightmare.
I have to Validate this format: 0-0000 0000 and/or 0-0000 0000/0 and/or
0-0000 0000/00
\A\d\-\d{4}\s\d{4}(?:\/\d{1,2})?\Z
- needs to be escaped, it's a range indicator. Don't use ^$ unless
you want to be tricked by multi-line matches, which I'm sure is not
what you want. For a simple regexp like the one you needed, the above
simple one is much better, fancy regexps for simple cases is kinda
annoying to manage.
Hi
.. somebody around who is easy with Reg. Exressions.
For me a nightmare.
I have to Validate this format: 0-0000 0000 and/or 0-0000 0000/0 and/or
0-0000 0000/00
\A\d\-\d{4}\s\d{4}(?:\/\d{1,2})?\Z
- needs to be escaped, it's a range indicator. Don't use ^$ unless
you want to be tricked by multi-line matches, which I'm sure is not
what you want. For a simple regexp like the one you needed, the above
simple one is much better, fancy regexps for simple cases is kinda
annoying to manage.
Thanks very much..
validates :project_number, :format => { :with => /\A\d\-\d{4}\s\d{4}(?:\/\d{1,2})?\Z/, :message => "Message"}
works perfect..