一个输入框能输入字符串,有如下要求
1.可以是0123456789,.中的任意一个
2.为了保证合法性,字符串最多只能包含一个","或者".",为了保证合法性,如果有"."必须在","之前
3.","(西方的小数点位)最多只能有两位有效数字
4.把这个字符串转化为国际标准数字,如“19,99”转换为"19.99",“1.999,99”转化为"1999.99"
最后谢谢各位了,分数不是一定的,只要能解决问题,再送上更多分数

解决方案 »

  1.   

    for exampleString[] data = {"19,99", "1.999,99", "12,999", "122.999", "20,00.99"}; //测试数据
    String regex = "\\d+[.]?\\d*([,]\\d{2})?"; //正则
    for (String s : data) {
        if (s.matches(regex)) {
            System.out.printf("[%s] is ok. ", s);
            s = s.replace(".", "").replace(",", ".");
            System.out.printf("after replace, [%s]\n", s);
        } else {
            System.out.printf("[%s] is not ok.\n", s);
        }
    }
      

  2.   

    import java.util.Scanner;public class TestOutStream
    {
    public static void main(String[] args)
    { Scanner s = new Scanner(System.in); String num = s.nextLine(); boolean b = num.matches("\\d+[\\.]?[\\d]+(,{1}[\\d]{2})|\\d*"); System.out.println(b); if (b)
    {
    num = num.replaceAll("\\.", "").replaceAll(",", "\\."); System.out.println(num);
    } }}
    应该问题不大,如果我没理解错题意的话,用户自己输入数字。
      

  3.   

    jquery插件库
    www.jeasyui.com
    可以单独使用里面的numberbox插件
    http://www.jeasyui.com/documentation/numberbox.php