Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

validating Year in java  RSS feed

 
ivin jacob
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ,

How can i validate whether a particulat integer is avalid year or not?

somthing like isValidYear(int)

please help
ivin
 
ivin jacob
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
valid year in the sence a valid year in our era in yyyy format.
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't think I understand what you're asking. "yyyy" might be a format that a number needs to adhere to if it is represented by a string, but the parameter in the method signature you showed is an int. Can you tell us the rule of what does and does not constitute a valid year?
 
ivin jacob
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
its actually a string
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could match it against a regular expression such as "[12][0-9]{3}". Depending on which values you consider to be valid, this could be tightened further.

Even simpler, you could parse it into an int, and then simply compare it numerically to the allowable lower and upper bounds.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!