• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Validation of Date and Month from input string

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

We are receiving string as MMDD format as an input. I would like to validate that it is correct date and moth combination(i. is should not be 0230 ;)) on schema level. Need a help to derive a pattern for that.

Thank you.
 
Ranch Hand
Posts: 734
7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Since YY or YYYY is not in the data, there would be no control of 0229 vs 0228 month... Even with YY or YYYY, that kind of control would be extremely tedious and "counter-productive" that that kind of control should (28-day Feb or 29-day Feb) better be relegated to the application itself if one needs fine-grained control. Otherwise, one would be contended  with 29 as max for 02 MM.

Having said that, what remains is to sit down and enumerate the 30-day, 31-day and 29-day month's patterns. Even though it is not very difficult, it requires a reasonable amount of easiness in working with regex. Here is how it can be done. Once you see it, you may be in a better position to understand how it is constructed and the line of reasoning.

Break it down into components separated by alternative "|" each of them deals with one kind of months.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic