常用正则表达

在线验证

常用正则表达

1
2
3
4
5
6
7
8
// isPositiveInt(正整数)
/^([1-9]([0-9]+)?)$/.test(val)
// isPositive(非负数)
/^(0|[1-9][0-9]*)(\.\d+)?$/.test(val)
// isNaturalNumber(自然数)
/^([0-9]|[1-9]([0-9]+)?)$/.test(val)
// isNumber(数字)
/^[+-]?(0|([1-9]\d*))(\.\d+)?$/.test(val)

本文作者: 孟 虎
本文链接: https://menghu1994.github.io/blog/2024/08/Tools/commonRegExp/
版权声明: 本博客所有文章除特别声明外,均采用 CC BY-SA 4.0 协议 ,转载请注明出处!