I am trying to validate a date like such.. yyyy-mm-dd. I am using this following. The date will turn out to a funny number 1043-22-02 instead of a normal year, month, date. Any suggestions
public final class DateValidation
{
protected static boolean isDate(
String string)
{
if (string == null)
return false;
if (string.indexOf("/") > -1)
{
try
{
SimpleDateFormat sdf = new SimpleDateFormat("yyyy/mm/dd");
sdf.setLenient(false);
Date dt = sdf.parse( string );
return true;
}
catch(Exception e)
{
return false;
}
}
else
{
try
{
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-mm-dd");
sdf.setLenient(false);
Date dt = sdf.parse( string );
return true;
}
catch(Exception e)
{
return false;
}
}
} //isDate
}