Al *_*yan 2 html regex pattern-matching
我正在处理表单验证并希望使用模式属性来验证输入字段。该字段具有以下条件:
那么确切的模式应该是什么RegEx
。我正在尝试使用以下代码,但如何实现百分比条件?
<input type="text"
pattern="[0-9]+([\.][0-9]{0,2})?"
title="This must be a number with up to 2 decimal places and/or %">
Run Code Online (Sandbox Code Playgroud)
你快到了。添加%?
到您的模式:
input:invalid {
color: red;
}
Run Code Online (Sandbox Code Playgroud)
<input type="text"
pattern="[0-9]+(\.[0-9]{1,2})?%?"
title="This must be a number with up to 2 decimal places and/or %">
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
12563 次 |
最近记录: |