首先要import java.util.regex.Pattern 和 java.util.regex.Matcher

  /**
     * 利用正则表达式判断字符串是否是数字
     * @param str
     * @return
     */
    public boolean isNumeric(String str){
           Pattern pattern = Pattern.compile("^[0-9]*$");
           Matcher isNum = pattern.matcher(str);
           if( !isNum.matches() ){
               return false;
           }
           return true;
    }

 效验Double类型

boolean isDouble(String str)
{
   try
   {
      Double.parseDouble(str);
      return true;
   }
   catch(NumberFormatException ex){}
   return false;
}

 

相关文章:

  • 2021-11-27
  • 2021-12-12
  • 2021-09-29
  • 2022-12-23
  • 2022-12-23
  • 2022-02-28
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-02-10
  • 2022-12-23
  • 2022-12-23
  • 2021-11-02
  • 2021-12-18
相关资源
相似解决方案