1 7 package com.inversoft.util.typevalidator; 8 9 10 import java.util.Locale ; 11 12 13 22 public class EmailTypeValidator extends BaseTypeValidator { 23 24 28 public static final String DEFAULT_MESSAGE = "Invalid email address"; 29 30 31 34 public EmailTypeValidator() { 35 } 37 38 39 49 protected String internalValidate(Object value, Object params, String message, 50 Locale locale, Object [] mesgParams) { 51 String localEmail = value.toString().trim(); 52 int at = localEmail.indexOf("@"); 53 int space = localEmail.indexOf(" "); 54 boolean valid = (at != -1 && at != 0 && 55 at != (localEmail.length() - 1) && space == -1); 56 if (valid) { 57 valid = (localEmail.indexOf("@", at + 1) == -1); 58 } 59 60 String error = null; 61 if (!valid) { 62 error = getErrorMessage(message, DEFAULT_MESSAGE, mesgParams); 63 } 64 65 return error; 66 } 67 } | Popular Tags |