This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

getting wrong values using matcher.group()

 
vardhan reddy
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
I am validating date using regex and I'm trying to get matcher groups and getting wrong values. Can anyone check and let me know what i'm doing wrong.



 
Jelle Klap
Bartender
Posts: 1951
7
Eclipse IDE Java
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Someone is going to inevitably mention this, so it might as well be me: why not just use (Simple)DateFormat?
 
vardhan reddy
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I'm planning to write generic class to validate any date format and DATE_PATTERN regex will be passed to validate method based on date format.
By using DateFormat, if parse (date format yyyymmdd) I will get but which is wrong date(month is wrong).

thanks for your reply.
 
Darryl Burke
Bartender
Posts: 5125
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
vardhan reddy wrote:By using DateFormat, if parse (date format yyyymmdd) I will get but which is wrong date(month is wrong).

No, it's right. What's the 1st day of the 13th month of 2012, with a lenient interpretation?
 
vardhan reddy
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It will give 1st date of next month, but i dont want that date and I want to display warning message 'Invalide date' something like this.
 
Jelle Klap
Bartender
Posts: 1951
7
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Then you should disable lenient parsing, using the setLenient() method.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic