• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to create a validate method to validate a string for null, notEmpty and with in specific length  RSS feed

 
Hindusthan Kamal
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Greeting to all,

I have a doubt,

My motive is to create a method that will check a string for null, isEmpty and also for maxLength, this should be done with a single method, if anything is wrong, it should throw a runtime exception.

I have done this for checking for null and empty,



Now I want to include the parameter for maxLength to check whether the length not exceeds the maxLength,

can any one help me with this.

My idea is to pass a third parameter as int or long, that will get the value for the maxLength and can put a condition, if the value for the maxLength is 0 means there is no need to check for maxLength condition

Is this will be a fine solution or you guys have any other solution to make this more refine ?
 
John Jai
Rancher
Posts: 1776
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yours is a good idea if you want to specify different max lengths for different strings. Else you could specify the max length as a static constant class variable.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!