001/*
002 *  Copyright 2010 Anyware Services
003 *
004 *  Licensed under the Apache License, Version 2.0 (the "License");
005 *  you may not use this file except in compliance with the License.
006 *  You may obtain a copy of the License at
007 *
008 *      http://www.apache.org/licenses/LICENSE-2.0
009 *
010 *  Unless required by applicable law or agreed to in writing, software
011 *  distributed under the License is distributed on an "AS IS" BASIS,
012 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 *  See the License for the specific language governing permissions and
014 *  limitations under the License.
015 */
016package org.ametys.plugins.forms.processing;
017
018/**
019 * Forms constants.
020 */
021public final class FormValidators
022{
023    
024    private FormValidators()
025    {
026        // Hides the default constructor.
027    }
028    
029    /**
030     * Get the integer validation pattern.
031     * @return the integer validation pattern.
032     */
033    public static final String getIntegerPattern()
034    {
035        return "^-?[0-9]+$";
036    }
037    
038    /**
039     * Get the float validation pattern.
040     * @return the float validation pattern.
041     */
042    public static final String getFloatPattern()
043    {
044        return "^-?[0-9]+(\\.[0-9]+)?$";
045    }
046    
047    /**
048     * Get the date validation pattern.
049     * @return the date validation pattern.
050     */
051    public static final String getDatePattern()
052    {
053        return "^([12][0-9][0-9][0-9])-([01][0-9])-([0123][0-9])$";
054    }
055    
056    /**
057     * Get the time validation pattern.
058     * @return the time validation pattern.
059     */
060    public static final String getTimePattern()
061    {
062        return "^([012][0-9]):([012345][0-9])$";
063    }
064    
065    /**
066     * Get the date and time validation pattern.
067     * @return the date and time validation pattern.
068     */
069    public static final String getDateTimePattern()
070    {
071        return "^([12][0-9][0-9][0-9])-([01][0-9])-([0123][0-9]) ([012][0-9]):([012345][0-9])$";
072    }
073    
074    /**
075     * Get the phone validation pattern.
076     * @return the phone validation pattern.
077     */
078    public static final String getPhonePattern()
079    {
080        return "^(\\+?\\(?[0-9]{1,3}\\)?([\\s]?)(\\(0\\))?|0)([\\s]?)([0-9\\-\\+\\s]{4,})+$";
081    }
082    
083    /**
084     * Get the date format pattern (understandable by java.util.SimpleDateFormat).
085     * @return the date format pattern.
086     */
087    public static final String getDateFormat()
088    {
089        return "yyyy-MM-dd";
090    }
091    
092    /**
093     * Get the time format pattern (understandable by java.util.SimpleDateFormat).
094     * @return the time format pattern.
095     */
096    public static final String getTimeFormat()
097    {
098        return "HH:mm";
099    }
100    
101    /**
102     * Get the date and time format pattern (understandable by java.util.SimpleDateFormat).
103     * @return the date and time format pattern.
104     */
105    public static final String getDateTimeFormat()
106    {
107        return "yyyy-MM-dd HH:mm";
108    }
109    
110}