如题 请帮写一个把 只允许输入 数字  和 点 不是小数点

解决方案 »

  1.   

    ^[\\.\\d]{0,}$(java字符串形式)
    可以匹配 "", "1", ".", "..", ".12", "1.2" 等形式,不知道是不是你想要的。
      

  2.   

    一段测试程序,供参考BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
    Pattern p = Pattern.compile("[\\d\\.]*");
    String s;
    while((s = r.readLine())!= null){
    Matcher m = p.matcher(s);
    System.out.println(m.matches()?"match":"not match");
    System.out.println(" ");
    }输出:
    hi
    not match
     
    3.4
    match
     
    5.6
    match
     
    d
    not match
     
    2.77b
    not match