01: /*
02: * $Id: EmailAddressPatternValidator.java 461075 2006-06-20 16:05:42Z ivaynberg $
03: * $Revision: 461075 $ $Date: 2006-06-20 18:05:42 +0200 (Tue, 20 Jun 2006) $
04: *
05: * ==============================================================================
06: * Licensed under the Apache License, Version 2.0 (the "License"); you may not
07: * use this file except in compliance with the License. You may obtain a copy of
08: * the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing, software
13: * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14: * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15: * License for the specific language governing permissions and limitations under
16: * the License.
17: */
18: package wicket.markup.html.form.validation;
19:
20: import java.util.regex.Pattern;
21:
22: import wicket.markup.html.form.FormComponent;
23:
24: /**
25: * Validator for checking the form/pattern of email addresses.
26: *
27: * @author Chris Turner
28: * @author Jonathan Locke
29: * @author Martijn Dashorst
30: */
31: public class EmailAddressPatternValidator extends PatternValidator {
32: private static final long serialVersionUID = 1L;
33:
34: /** Singleton instance */
35: private static final EmailAddressPatternValidator instance = new EmailAddressPatternValidator();
36:
37: /**
38: * @return Instance of emailadress validator
39: */
40: public static EmailAddressPatternValidator getInstance() {
41: return instance;
42: }
43:
44: /**
45: * Protected constructor to force use of static singleton accessor method.
46: * Or override it to implement resourceKey(Component)
47: */
48: protected EmailAddressPatternValidator() {
49: super (
50: "^[_A-Za-z0-9-]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9-]+(\\.[A-Za-z0-9-]+)*((\\.[A-Za-z]{2,}){1}$)",
51: Pattern.CASE_INSENSITIVE);
52: }
53:
54: /**
55: * @see wicket.markup.html.form.validation.AbstractValidator#resourceKey(wicket.markup.html.form.FormComponent)
56: */
57: protected String resourceKey(FormComponent formComponent) {
58: return "EmailAddressPatternValidator";
59: }
60: }
|