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 FrenchLastNameFieldValidator extends NuitonFieldValidatorSupport {
38
39 protected static String LAST_NAME_REGEXP = "[^\\d]+";
40
41 protected static Pattern p = Pattern.compile(LAST_NAME_REGEXP);
42
43 @Override
44 public void validateWhenNotSkip(Object object) throws ValidationException {
45
46 String fieldName = getFieldName();
47 Object value = getFieldValue(fieldName, object);
48
49 if (value == null) {
50
51 return;
52 }
53 if (value instanceof String) {
54 if ("".equals(value)) {
55
56 return;
57 }
58 Matcher m = p.matcher((String) value);
59 if (!m.matches()) {
60 addFieldError(fieldName, object);
61 }
62 } else {
63 addFieldError(fieldName, object);
64 }
65 }
66
67 @Override
68 public String getValidatorType() {
69 return "frenchLastName";
70 }
71 }