<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    konhon

    忘掉過去,展望未來。找回自我,超越自我。
    逃避不一定躲的過, 面對不一定最難過, 孤單不一定不快樂, 得到不一定能長久, 失去不一定不再擁有, 可能因為某個理由而傷心難過, 但我卻能找個理由讓自己快樂.

    Google

    BlogJava 首頁 新隨筆 聯系 聚合 管理
      203 Posts :: 0 Stories :: 61 Comments :: 0 Trackbacks

     

    import java.text.*;
    import java.util.
    *;

    public class StringFormat {
        
    private static SimpleDateFormat dateFormat = new SimpleDateFormat();
        
    private static DecimalFormat numberFormat = new DecimalFormat();

        
    /**//**
         * Returns true if the specified date string represents a valid
         * date in the specified format, using the default Locale.
         *
         * @param dateString a String representing a date/time.
         * @param dateFormatPattern a String specifying the format to be used
         *   when parsing the dateString. The pattern is expressed with the
         *   pattern letters defined for the java.text.SimpleDateFormat class.
         * @return true if valid, false otherwise
         
    */

        
    public static boolean isValidDate(String dateString, 
            String dateFormatPattern) 
    {
            Date validDate 
    = null;
            synchronized (dateFormat) 

                
    try {
                    dateFormat.applyPattern(dateFormatPattern);
                    dateFormat.setLenient(
    false);
                    validDate 
    = dateFormat.parse(dateString);
                }

                
    catch (ParseException e) {
                    
    // Ignore and return null
                }

            }

            
    return validDate != null;
        }

        
        
    /**//**
         * Returns true if the specified number string represents a valid
         * integer in the specified range, using the default Locale.
         *
         * @param numberString a String representing an integer
         * @param min the minimal value in the valid range
         * @param max the maximal value in the valid range
         * @return true if valid, false otherwise
         
    */

        
    public static boolean isValidInteger(String numberString, int min, 
            
    int max) {
            Integer validInteger 
    = null;
            
    try {
                Number aNumber 
    = numberFormat.parse(numberString);
                
    int anInt = aNumber.intValue();
                
    if (anInt >= min && anInt <= max) {
                    validInteger 
    = new Integer(anInt);
                }

            }

            
    catch (ParseException e) {
                
    // Ignore and return null
            }

            
    return validInteger != null;
        }

        
        
    /**//**
         * Returns true if the string is in the format of a valid SMTP
         * mail address: only one at-sign, except as the first or last
         * character, no white-space and at least one dot after the
         * at-sign, except as the first or last character.
         * <p>
         * Note! This rule is not always correct (e.g. on an intranet it may 
         * be okay with just a name) and it does not guarantee a valid Internet 
         * email address but it takes care of the most obvious SMTP mail 
         * address format errors.
         *
         * @param mailAddr a String representing an email address
         * @return true if valid, false otherwise
         
    */

        
    public static boolean isValidEmailAddr(String mailAddr) {
        
    if (mailAddr == null{
            
    return false;
        }


            boolean isValid 
    = true;
        mailAddr 
    = mailAddr.trim();

        
    // Check at-sign and white-space usage
        int atSign = mailAddr.indexOf('@');
        
    if (atSign == -1 || 
            atSign 
    == 0 ||
            atSign 
    == mailAddr.length() -1 ||
            mailAddr.indexOf(
    '@', atSign + 1!= -1 ||
            mailAddr.indexOf(
    ' '!= -1 ||
            mailAddr.indexOf(
    '\t'!= -1 ||
            mailAddr.indexOf(
    '\n'!= -1 ||
            mailAddr.indexOf(
    '\r'!= -1{
            isValid 
    = false;
        }

        
    // Check dot usage
        if (isValid) {
            mailAddr 
    = mailAddr.substring(atSign + 1);
            
    int dot = mailAddr.indexOf('.');
            
    if (dot == -1 || 
            dot 
    == 0 ||
            dot 
    == mailAddr.length() -1{
            isValid 
    = false;
            }

        }

            
    return isValid;
        }

        
    public static Date toDate(String dateString, String dateFormatPattern) 
            throws ParseException 
    {
            Date date 
    = null;
            
    if (dateFormatPattern == null{
                dateFormatPattern 
    = "yyyy-MM-dd";
            }

            synchronized (dateFormat) 

                dateFormat.applyPattern(dateFormatPattern);
                dateFormat.setLenient(
    false);
                date 
    = dateFormat.parse(dateString);
            }

            
    return date;
        }

        
    /**
         * Converts a String to a Number, using the specified pattern.
         * (see java.text.NumberFormat for pattern description) and the
         * default Locale.
         *
         * @param numString the String to convert
         * @param numFormatPattern the pattern
         * @return the corresponding Number
         * @exception ParseException, if the String doesn't match the pattern
         
    */

        
    public static Number toNumber(String numString, String numFormatPattern) 
            throws ParseException 
    {
            Number number 
    = null;
            
    if (numFormatPattern == null{
                numFormatPattern 
    = "######.##";
            }

            synchronized (numberFormat) 

                numberFormat.applyPattern(numFormatPattern);
                number 
    = numberFormat.parse(numString);
            }

            
    return number;
        }
    posted on 2005-08-16 21:01 konhon 優華 閱讀(375) 評論(0)  編輯  收藏 所屬分類: Java
    主站蜘蛛池模板: 亚洲激情在线观看| 国产免费69成人精品视频| 日韩精品亚洲aⅴ在线影院| 亚洲国产欧美国产综合一区 | 亚洲成A人片77777国产| 亚洲手机中文字幕| 久久久久久噜噜精品免费直播| 在线免费观看色片| 亚洲AV无码乱码麻豆精品国产| 999久久久免费精品播放| 亚洲中文字幕视频国产| 高清免费久久午夜精品| 国产成人高清精品免费软件| 亚洲中字慕日产2021| 无码中文字幕av免费放dvd| www国产亚洲精品久久久日本| 国产成人va亚洲电影| 小小影视日本动漫观看免费| 亚洲av成本人无码网站| 日产乱码一卡二卡三免费| 亚洲AV无码一区二区三区久久精品 | 最近中文字幕免费2019| 亚洲v高清理论电影| 久久爰www免费人成| 亚洲欧洲一区二区| 国产免费久久久久久无码| 国产jizzjizz免费看jizz| 亚洲精品人成网在线播放影院 | 91成人免费观看| 亚洲精品熟女国产| 97在线观免费视频观看| 亚洲国产精品久久久久秋霞影院 | 成人无码区免费视频观看| 色老板亚洲视频免在线观| 成人毛片免费播放| 黄网站在线播放视频免费观看| 亚洲精品网站在线观看不卡无广告| 和老外3p爽粗大免费视频| 亚洲国产人成网站在线电影动漫| 久久免费观看国产精品| 精品亚洲综合在线第一区|