正則表達式驗證字符串是否為數字(包含正負數)


 1 /**
 2      * 判斷是否為數字(正負數都行)
 3      * @param str 需要驗證的字符串
 4      * @return
 5      */
 6     public static boolean isNumeric(String str){ 
 7        Pattern pattern = Pattern.compile("^[-\\+]?[\\d]*$"); 
 8        Matcher isNum = pattern.matcher(str);
 9        if( !isNum.matches() ){
10            return false; 
11        } 
12        return true; 
13     }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM