0

I've tried to validate a own format (day,day,number,number) in my Ruby-Controller. The day has always two numbers (4-> 04). What i tried is the following:

... format: { with: /\A(0[1-9]|[12]\d|3[01]){2}\p{L}{2}\z/, message: "wrong format" }

(0[1-9]|[12]\d|3[01]) comes from https://stackoverflow.com/a/6077026. This should validate the day. Then i add {2} because i want exactly two of these day-inputs. Finally \p{L} with {2} for two letters.

Does anyone know what i do wrong?

3131zz should be accepted. 3231zz not.

Thanks

Community
  • 1
  • 1
Tommy
  • 2,355
  • 1
  • 19
  • 48

2 Answers2

1

I have put your regular expression on : http://rubular.com/

And 3131zz is accepted whereas 3231zz is not... so it seems that your regex is correct.

What kind of error do you have?

CRABOLO
  • 8,605
  • 39
  • 41
  • 68
Pipala
  • 197
  • 1
  • 9
1

How do you come to the conclusion, that your format does not work? If I validate it using rubular it works: rubular example If you are having trouble, I feel it is not with your regular expression but either with your input string being wrong or maybe some other validation which fails.

Milan Köpke
  • 1,133
  • 7
  • 8
  • I finally found my error. I missed something that i later wrote to stackoverflow. Thanks anyhow. – Tommy May 27 '14 at 09:58