/** * * Copyright (c) 2003 University of Mancester. * @author Kevin Garwood (garwood@cs.man.ac.uk) * */ package pedro.validation; import java.lang.NumberFormatException; /** * checks whether field value is a valid float * @author Kevin Garwood * @date * @version 1.0 */ /* Code RoadMap: Section Constants Section Properties Section Construction Section Accessors Section Mutators Section Validation Section Errors Section Interfaces Section Overload */ public class FloatValidator extends AbstractValidator { // ========================================== // Section Constants // ========================================== // ========================================== // Section Properties // ========================================== // ========================================== // Section Construction // ========================================== // ========================================== // Section Accessors // ========================================== // ========================================== // Section Mutators // ========================================== // ========================================== // Section Validation // ========================================== // ========================================== // Section Errors // ========================================== // ========================================== // Section Interfaces // ========================================== //Validator public String validate(String value) { //check for empty field String error = validateRequiredField(value); if ( error != null) { return error; } //end if () if ( isEmpty(value) == true) { //field can be empty return null; } //end if () try { float number = Float.parseFloat(value); //value parsed ok so no errors return null; } catch (NumberFormatException err) { return( value + " is not a valid float for " + getFieldName() ); } // end try-catch } // ========================================== // Section Overload // ========================================== }