1

i am new to regex being used in validation.xml in struts 1.0. that said, what does the following mean? in terms of xx/xx/xxxx?

<constant-value>^\d{1,2}(\-|\/|\.)\d{1,2}\1\d{4}$</constant-value>
LaneLane
  • 335
  • 4
  • 16

1 Answers1

1

This appears to be a date validator in any of the following formats:

dd-mm-yyyy
dd/mm/yyyy
dd.mm.yyyy

mm-dd-yyyy
mm/dd/yyyy
mm.dd.yyyy

PS: It allows month or date digits to be single or double digits.

Recommended Regex Reference

anubhava
  • 664,788
  • 59
  • 469
  • 547
  • what if i what it to be only in mm/dd/yyyy? – LaneLane Nov 13 '13 at 14:40
  • That is probably possible with regex but it will be an awfully long regex validating all possible days of a month like July/31, Nov/30. Moreover for leap year that will fail. IMO better to validate dates using code while using a regex like above to make sure basic syntax is there. – anubhava Nov 13 '13 at 14:44
  • okthanks. do i have to look at `validator-rules.xml`? there is a `validator=date` and `datePatternStrict` so should I be concerned too? – LaneLane Nov 13 '13 at 14:46
  • Actually `validator=date` seems to the best fit for you as per: http://struts.apache.org/release/2.1.x/docs/date-validator.html – anubhava Nov 13 '13 at 15:10
  • @anubhava Wrong version of Struts. – Dave Newton Nov 13 '13 at 17:45
  • @DaveNewton: Ah thanks, forgot that OP is using Struts 1.0 – anubhava Nov 13 '13 at 17:50
  • @LaneLane: In that case use above regex for basic date validation. – anubhava Nov 13 '13 at 17:50