Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

修改实例:小数点后几位 #4

Closed
cuilanxin opened this issue Nov 25, 2021 · 7 comments
Closed

修改实例:小数点后几位 #4

cuilanxin opened this issue Nov 25, 2021 · 7 comments

Comments

@cuilanxin
Copy link
Contributor

❌正则:^(0|[1-9]\d*)(.\d+)?$

@jaywcjlove
Copy link
Owner

精简一下

/^(0|[1-9]\d*)(.\d+)$/.test(0.23)
// => true

原示例修改

- /^[0-9]+(.[0-9]{2})?$/.test(0.000) //=> true
+ /^[0-9]+(.[0-9]{2})$/.test(0.000) //=> false
/^[0-9]+(.[0-9]{2})$/.test(0.000) //=> false

@jaywcjlove
Copy link
Owner

/^(0|[1-9]\d*)(.\d+)$/.test(0.00)
//=> false

你这个正则也不太行
@cuilanxin

jaywcjlove added a commit that referenced this issue Nov 25, 2021
jaywcjlove added a commit that referenced this issue Nov 25, 2021
@cuilanxin
Copy link
Contributor Author

cuilanxin commented Nov 25, 2021

换成字符串就行了,而且我觉得 /^(0|[1-9]\d*)(.\d+)?$/ 应该需要,在写业务中,用来校验表单的

/^(0|[1-9]\d*)(.\d+)$/.test('0.00')
//=> true

@jaywcjlove
Copy link
Owner

@cuilanxin 已经更改

@cuilanxin
Copy link
Contributor Author

非零,俩位,最大 99999999.99

/^(0|[1-9]\d{0,7}).?(([1-9]{1,2}?)|(0[1-9]))$/g

@jaywcjlove
Copy link
Owner

@cuilanxin 已添加

@cuilanxin
Copy link
Contributor Author

cuilanxin commented Jul 12, 2022

非零,最多俩位小数

/^(?!^0(.0{1,2})?$)\d*(\.\d{1,2})?$/g

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants