KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > infoglue > cms > util > validators > EmailValidator


1 /* ===============================================================================
2  *
3  * Part of the InfoGlue Content Management Platform (www.infoglue.org)
4  *
5  * ===============================================================================
6  *
7  * Copyright (C)
8  *
9  * This program is free software; you can redistribute it and/or modify it under
10  * the terms of the GNU General Public License version 2, as published by the
11  * Free Software Foundation. See the file LICENSE.html for more information.
12  *
13  * This program is distributed in the hope that it will be useful, but WITHOUT
14  * ANY WARRANTY, including the implied warranty of MERCHANTABILITY or FITNESS
15  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License along with
18  * this program; if not, write to the Free Software Foundation, Inc. / 59 Temple
19  * Place, Suite 330 / Boston, MA 02111-1307 / USA.
20  *
21  * ===============================================================================
22  */

23
24 package org.infoglue.cms.util.validators;
25
26
27 public class EmailValidator extends StringValidator
28 {
29   // --- [Constants] -----------------------------------------------------------
30

31   // perl5 patterns
32
private static final String JavaDoc SEPARATOR = "\\.";
33   private static final String JavaDoc WORD = "[a-zA-Z][a-zA-Z0-9_-]*";
34   private static final String JavaDoc WORDS = WORD + "(" + SEPARATOR + WORD + ")*";
35   private static final String JavaDoc IP_PART = "[0-9]{1,3}";
36   private static final String JavaDoc IP = IP_PART + "(" + SEPARATOR + IP_PART + "){3}";
37   private static final String JavaDoc DOMAIN = "(" + IP + "|" + WORDS + ")";
38   private static final String JavaDoc LOCAL = WORDS;
39   private static final String JavaDoc ADDRESS = "^" + LOCAL + "@" + DOMAIN + "$";
40
41   // error codes
42
private static final String JavaDoc INVALID_EMAIL_ADDRESS_ERROR_CODE = "305";
43
44
45
46   // --- [Attributes] ----------------------------------------------------------
47
// --- [Static] --------------------------------------------------------------
48
// --- [Constructors] --------------------------------------------------------
49

50   /**
51    * <todo>remove?</todo>
52    */

53   public EmailValidator(String JavaDoc fieldName) {
54     this(fieldName, true);
55   }
56
57   /**
58    * <todo>remove?</todo>
59    */

60   public EmailValidator(String JavaDoc fieldName, boolean isRequired) {
61     super(fieldName, isRequired);
62     initializePattern(ADDRESS, INVALID_EMAIL_ADDRESS_ERROR_CODE);
63   }
64
65   /**
66    *
67    */

68   public EmailValidator(String JavaDoc fieldName, boolean isRequired, int upperLengthLimit) {
69     super(fieldName, isRequired, upperLengthLimit);
70     initializePattern(ADDRESS, INVALID_EMAIL_ADDRESS_ERROR_CODE);
71   }
72
73
74
75   // --- [Public] --------------------------------------------------------------
76
// --- [X implementation] ----------------------------------------------------
77
// --- [X Overrides] ---------------------------------------------------------
78
// --- [Package protected] ---------------------------------------------------
79
// --- [Private] -------------------------------------------------------------
80
// --- [Protected] -----------------------------------------------------------
81
// --- [Inner classes] -------------------------------------------------------
82
}
Popular Tags