1 12 package org.eclipse.jface.internal.databinding.provisional.validation; 13 14 import org.eclipse.jface.internal.databinding.internal.BindingMessages; 15 16 17 20 public class String2FloatValidator implements IValidator { 21 22 public ValidationError isPartiallyValid(Object fragment) { 23 if (((String )fragment).matches("\\-?[0-9]*\\.?[0-9]*([0-9]+[e|E]\\-?([0-9]+\\.)?[0-9]*)?")) return null; 25 26 return ValidationError.error(getHint()); 27 } 28 29 public ValidationError isValid(Object value) { 30 try { 31 Float.parseFloat((String )value); 32 return null; 33 } catch (Exception e) { 34 return ValidationError.error(getHint()); 35 } 36 } 37 38 private String getHint() { 39 return BindingMessages.getString("Validate_Like") + BindingMessages.getString("Validate_Number_Examples") + Float.MIN_VALUE + 42 ", " + Float.MAX_VALUE + "."; } 44 45 } 46 | Popular Tags |