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字符串格式化方法
目录
文章列表
1 React Native之API学习Linking跨App的通信方法(适配Android & iOS)
React Native之API学习Linking跨App的通信方法(适配Android & iOS)
2
Android在代码中如何获取应用签名及sha1值
Android在代码中如何获取应用签名及sha1值
3
uni-app HTTP请求工具 luch-request
uni-app HTTP请求工具 luch-request
4
Android NDK基础13:JNI异常处理_JNI缓存策略
Android NDK基础13:JNI异常处理_JNI缓存策略
5
Jmeter压测
Jmeter压测
最新评论
一位WordPress评论者
一位WordPress评论者
2月12日
您好,这是一条评论。若需要审核、编辑或删除评论,请访问仪表盘的评论界面。评论者头像来自 Gravatar。