1 23 24 package org.infoglue.cms.util.validators; 25 26 27 public class EmailValidator extends StringValidator 28 { 29 31 private static final String SEPARATOR = "\\."; 33 private static final String WORD = "[a-zA-Z][a-zA-Z0-9_-]*"; 34 private static final String WORDS = WORD + "(" + SEPARATOR + WORD + ")*"; 35 private static final String IP_PART = "[0-9]{1,3}"; 36 private static final String IP = IP_PART + "(" + SEPARATOR + IP_PART + "){3}"; 37 private static final String DOMAIN = "(" + IP + "|" + WORDS + ")"; 38 private static final String LOCAL = WORDS; 39 private static final String ADDRESS = "^" + LOCAL + "@" + DOMAIN + "$"; 40 41 private static final String INVALID_EMAIL_ADDRESS_ERROR_CODE = "305"; 43 44 45 46 50 53 public EmailValidator(String fieldName) { 54 this(fieldName, true); 55 } 56 57 60 public EmailValidator(String fieldName, boolean isRequired) { 61 super(fieldName, isRequired); 62 initializePattern(ADDRESS, INVALID_EMAIL_ADDRESS_ERROR_CODE); 63 } 64 65 68 public EmailValidator(String fieldName, boolean isRequired, int upperLengthLimit) { 69 super(fieldName, isRequired, upperLengthLimit); 70 initializePattern(ADDRESS, INVALID_EMAIL_ADDRESS_ERROR_CODE); 71 } 72 73 74 75 } | Popular Tags |