Java tutorial
/* * SurveyPanel * Copyright (C) 2009 Serge Tan Panza * All rights reserved. * License: GNU/GPL License v3 , see LICENSE.txt * SurveyPanel is free software. This version may have been modified pursuant * to the GNU General Public License, and as distributed it includes or * is derivative of works licensed under the GNU General Public License or * other free or open source software licenses. * See COPYRIGHT.txt for copyright notices and details. * */ package com.surveypanel.form.validation; import java.util.Locale; import java.util.Map; import org.apache.commons.validator.GenericValidator; import com.surveypanel.form.FormData; import com.surveypanel.form.QuestionImpl; /** * @author stanpanza * */ public class EmailValidation extends Validator { @Override public void validate(QuestionImpl question, FormData formData, Locale locale, Map<String, String> config, ValidationResult validationResult) throws Exception { String errorMsg = config.containsKey("errorKey") ? config.get("errorKey") : "form.error.email"; if (!question.isMulti()) { Object value = formData.getValue(); if (value instanceof String) { if (!GenericValidator.isEmail((String) value)) { validationResult .addError(qDefinition.getText(errorMsg, new Object[] { question.getName() }, locale)); } } } } }