001/*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  You may obtain a copy of the License at
008 *
009 *      http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.apache.wicket.validation.validator;
018
019import java.util.regex.Pattern;
020
021/**
022 * Validator for checking the form/pattern of email addresses.
023 * 
024 * NOTICE: This validator only checks the most commonly used email address patterns. For a validator
025 * that can check the entire range of rfc compliant email addresses see
026 * <code>org.apache.wicket.extensions.validation.validator.RfcCompliantEmailAddressValidator</code>
027 *
028 * <p>Also see org.apache.wicket.extensions.validation.validator.RfcCompliantEmailAddressValidator</p>
029 *
030 * @author Chris Turner
031 * @author Jonathan Locke
032 * @author Martijn Dashorst
033 * @author Al Maw
034 *
035 *
036 * @since 1.3
037 */
038public class EmailAddressValidator extends PatternValidator
039{
040        private static final long serialVersionUID = 1L;
041
042        /** singleton instance */
043        private static final EmailAddressValidator INSTANCE = new EmailAddressValidator();
044
045        /**
046         * Retrieves the singleton instance of <code>EmailAddressValidator</code>.
047         * 
048         * @return the singleton instance of <code>EmailAddressValidator</code>
049         */
050        public static EmailAddressValidator getInstance()
051        {
052                return INSTANCE;
053        }
054
055        /**
056         * Protected constructor to force use of static singleton accessor. Override this constructor to
057         * implement resourceKey(Component).
058         */
059        protected EmailAddressValidator()
060        {
061                super(
062                        "^[_A-Za-z0-9-]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9-]+(\\.[A-Za-z0-9-]+)*((\\.[A-Za-z]{2,}){1}$)",
063                        Pattern.CASE_INSENSITIVE);
064        }
065}