Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在使用正则表达式验证文本框文本。格式是x.xxxx,目前我正在使用@"\d{1}.\d{1,4}",但现在我想更改表达式以允许x,如果他们按下.,那么它应该验证\d{1,4}.
x.xxxx
@"\d{1}.\d{1,4}"
x
.
\d{1,4}
在 JavaScript 中,您使用 /^\d(\.\d{1,4})?$/. 在 C# 中,您可以使用@"^\d(\.\d{1,4})?$"
/^\d(\.\d{1,4})?$/
@"^\d(\.\d{1,4})?$"
试试这个
// Optional deciaml points var regexp = /^\d+(\.\d{1,4})?$/; regexp.test('13.5454')
这允许在小数点后最多 4 位。但小数位是可选的