1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 package org.nuiton.validator.xwork2.field;
23
24 import com.opensymphony.xwork2.validator.ValidationException;
25
26 import java.util.regex.Matcher;
27 import java.util.regex.Pattern;
28
29
30
31
32
33
34
35
36
37 public class FrenchCityNameFieldValidator extends NuitonFieldValidatorSupport {
38
39 protected static String CITY_NAME_REGEXP = "[^\\d]+";
40
41 protected static Pattern p = Pattern.compile(CITY_NAME_REGEXP);
42
43
44
45 @Override
46 public void validateWhenNotSkip(Object object) throws ValidationException {
47
48 String fieldName = getFieldName();
49 Object value = getFieldValue(fieldName, object);
50
51 if (value == null) {
52
53 return;
54 }
55 if (value instanceof String) {
56 if ("".equals(value)) {
57
58 return;
59 }
60 Matcher m = p.matcher((String) value);
61 if (!m.matches()) {
62 addFieldError(fieldName, object);
63 }
64 } else {
65 addFieldError(fieldName, object);
66 }
67 }
68
69 @Override
70 public String getValidatorType() {
71 return "frenchCityName";
72 }
73 }