1 12 package org.eclipse.jface.internal.databinding.provisional.validation; 13 14 import java.math.BigDecimal ; 15 16 import org.eclipse.jface.internal.databinding.internal.BindingMessages; 17 18 19 24 public class String2BigDecimalValidator implements IValidator { 25 26 29 public ValidationError isPartiallyValid(Object fragment) { 30 if (((String )fragment).matches("\\-?[0-9]*\\.?[0-9]*([0-9]+[e|E]\\-?([0-9]+\\.)?[0-9]*)?")) return null; 32 33 return ValidationError.error(getHint()); 34 } 35 36 39 public ValidationError isValid(Object value) { 40 try { 41 new BigDecimal ((String )value); 42 return null; 43 } catch (Throwable t) { 44 return ValidationError.error(getHint()); 45 } 46 } 47 48 private String getHint() { 49 return BindingMessages.getString("Validate_Like") + BindingMessages.getString("Validate_Number_Examples"); } 52 53 } 54 | Popular Tags |