Consultor Eletrônico



Kbase 17948: Apptivity: How-To verify a date from a textfield
Autor   Progress Software Corporation - Progress
Acesso   Público
Publicação   5/19/1998
Apptivity: How-To verify a date from a textfield

INTRODUCTION:
=============
It might be needed to check a field on a valid date entry. This K-base
will show how-to change a Textfield to a date for verification.


//Creates a DateFormat in the UK timeZone.

java.text.SimpleDateFormat CheckFormat
= new java.text.SimpleDateFormat ("dd/MM/yyyy",java.util.Locale.UK);

// The next line is to set the behavior to use the format in a strict
// way. Otherwise, a month value of 13 would be treated as January
// next year.

CheckFormat.setLenient(false);
String dateString = null;
java.util.Date dateToTest = null;
try{
dateString = tf_Date.getText();
dateToTest = CheckFormat.parse(dateString);
}
catch(java.text.ParseException p){
System.out.println("Wrong Parsing");
}
catch(java.lang.IllegalArgumentException d){
System.out.println("The date is wrong");
}
catch(Exception e){
e.printStackTrace();
}
if (dateToTest == null){
System.out.println("The date is Wrong");
}
else{
System.out.println("The date is OK");
}

TBO
05/19/1998