Notice: 函数 WP_Scripts::localize 的调用方法不正确$l10n 参数必须是一个数组。若要将任意数据传递给脚本,请改用 wp_add_inline_script() 函数。 请查阅调试 WordPress来获取更多信息。 (这个消息是在 5.7.0 版本添加的。) in /data/www/appblog/wp-includes/functions.php on line 6131

JS控制浮点数输入正则

需求:

1、过滤以0开头
2、去除所有非数字和小数点的字符
3、去掉重复的小数点

JS实时控制浮点数输入

amountWatcher (val, oldVal) {
  console.log(val)
  this.order.amount = val.replace(/^[0]+/, '')
  this.order.amount = this.order.amount.replace(/[^\d.]|\.(?=[^.]*\.)/g, '')
}

Java校验字符串实现

String[] source = { "1,736, 233.00", " 236. 233.73", "36,233.235", "34.00" };
String[] result = new String[source.length];
for (int i = 0; i < source.length; i++) {
    result[i] = source[i].replaceAll("([^\\d\\.]|\\.(?=[^\\.]*\\.))", "");
}
System.out.println(Arrays.toString(result));
// [1736233.00, 236233.73, 36233.235, 34.00]
上一篇 Nodejs urlencode模块url加密解密
下一篇 JS字符串格式化方法