案例:做一个金额的匹配,需要将整数位和小数位作为参数。
function validation(value,integer,decimals){
var integer = integer || 13;
var decimals = decimals || 2;
var str = "(^\\d{1,"+integer+"}(\\.\\d{0,"+decimals+"})\?)$";
var reg = new RegExp(str);
return reg.test(value);
}