All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.opensymphony.xwork2.validator.validators.EmailValidator Maven / Gradle / Ivy

There is a newer version: 6.4.0
Show newest version
/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *  http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */
package com.opensymphony.xwork2.validator.validators;

/**
 * 
 * EmailValidator checks that a given String field, if not empty, is a valid email address.
 *
 * The regular expression used to validate that the string is an email address is:
 *
 * 
 * \\b^['_a-z0-9-\\+]+(\\.['_a-z0-9-\\+]+)*@[a-z0-9-]+(\\.[a-z0-9-]+)*\\.([a-z]{2,6})$\\b
 * 
* * You can also specify expression, caseSensitive and trim params as a OGNL expression, see the example below. * * * * *
    *
  • fieldName - The field name this validator is validating. Required if using Plain-Validator Syntax otherwise not required
  • *
* Check also documentation of the RegexpValidator for more details - the EmailValidator bases on it. * * * * Do not use ${regexExpression}, ${caseSensitiveExpression} and ${trimExpression} as an expression as this will turn into infinitive loop! * * *
 * 
 *     <!-- Plain Validator Syntax -->
 *     <validators>
 *         <validator type="email">
 *             <param name="fieldName">myEmail</param>
 *             <message>Must provide a valid email</message>
 *         </validator>
 *     </validators>
 *     
 *     <!-- Field Validator Syntax -->
 *     <field name="myEmail">
 *        <field-validator type="email">
 *           <message>Must provide a valid email</message>
 *        </field-validator>
 *     </field>
 *
 *     <!-- Field Validator Syntax with expressions -->
 *     <!-- Only available when used with xml based configuration, if you want to have the same
 *             flexibility with annotations use @RegexFieldValidator instead -->
 *     <field name="myEmail">
 *        <field-validator type="email">
 *           <param name="regexExpression">${emailPattern}</param> <!-- will be evaluated as: String getEmailPattern() -->
 *           <param name="caseSensitiveExpression">${emailCaseSensitive}</param> <!-- will be evaluated as: boolean getEmailCaseSensitive() -->
 *           <param name="trimExpression">${trimEmail}</param> <!-- will be evaluated as: boolean getTrimEmail() -->
 *           <message>Must provide a valid email</message>
 *        </field-validator>
 *     </field>
 * 
 * 
* * @author jhouse * @author tm_jee * @version $Date$ $Id$ */ public class EmailValidator extends RegexFieldValidator { public static final String EMAIL_ADDRESS_PATTERN = "\\b^['_a-z0-9-\\+]+(\\.['_a-z0-9-\\+]+)*@[a-z0-9-]+(\\.[a-z0-9-]+)*\\.([a-z]{2,6})$\\b"; public EmailValidator() { setRegex(EMAIL_ADDRESS_PATTERN); setCaseSensitive(false); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy