Java 正則校驗整數,且小數點只能是2位


 1 //金額驗證  
 2 public static boolean isNumber(String str){   
 3      Pattern pattern=Pattern.compile("^(([1-9]{1}\\d*)|([0]{1}))(\\.(\\d){0,2})?$"); // 判斷小數點后2位的數字的正則表達式  
 4      Matcher match=pattern.matcher(str);   
 5      if(match.matches()==false){   
 6         return false;   
 7      }else{   
 8         return true;   
 9      }   
10  }  

 


免責聲明!

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



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