comparison flys-client/src/main/java/de/intevation/flys/client/client/utils/DoubleValidator.java @ 2929:0ef4753e5515

Improved manual wsp input validation. flys-client/trunk@4830 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Thu, 28 Jun 2012 15:44:10 +0000
parents 4f4d29404dba
children a30d77d86386
comparison
equal deleted inserted replaced
2928:f0c7c52203c0 2929:0ef4753e5515
14 */ 14 */
15 public class DoubleValidator implements Validator { 15 public class DoubleValidator implements Validator {
16 16
17 /** The interface that provides i18n messages. */ 17 /** The interface that provides i18n messages. */
18 protected FLYSConstants MSG = GWT.create(FLYSConstants.class); 18 protected FLYSConstants MSG = GWT.create(FLYSConstants.class);
19
20
21 /** Statically determine doubility of String value. */
22 public static boolean isDouble(Object obj) {
23 if (obj == null) {
24 return false;
25 }
26
27 boolean valid = true;
28 String v = obj.toString();
29
30 NumberFormat f = NumberFormat.getDecimalFormat();
31
32 try {
33 if (v == null) {
34 throw new NumberFormatException("empty");
35 }
36
37 double value = f.parse(v);
38 }
39 catch (NumberFormatException nfe) {
40 valid = false;
41 }
42 return valid;
43
44 }
19 45
20 /** 46 /**
21 * 47 *
22 */ 48 */
23 public boolean validate(FormItem item, Map errors) { 49 public boolean validate(FormItem item, Map errors) {

http://dive4elements.wald.intevation.org