简体   繁体   English

HTML5模式属性不起作用

[英]HTML5 pattern attribute not working

I have a form on my webpage that needs to make sure that the text a user is entering is in the proper format; 我的网页上有一个表单,需要确保用户输入的文本格式正确; however, it doesn't seem to be preventing the form submission when data of an incorrect format is entered. 但是,当输入格式错误的数据时,似乎并不能阻止表单提交。 For example, the input needs to be a time of the format HH:MM am/pm and when I submit the form with a value of "a" in the field, it accepts the value when it shouldn't be. 例如,输入的时间必须为HH:MM am / pm格式,并且当我在字段中提交值“ a”的表单时,它接受该时间的值,而不应该接受。

Below is the code for the input: 以下是输入的代码:

<input id='timepicker' class="required" type='text' data-ng-model = "time" name='timepicker' pattern="(1[0-2]|[1-9]):[0-5][0-9](\\s)?(?i)(am|pm)" title="Time in HH:MM am/pm format" required>

Any help would be greatly appreciated 任何帮助将不胜感激

\\s不能转义(不是Java),不支持(?i)

pattern="(1[0-2]|0?[1-9]):[0-5][0-9]\s?[aApP][mM]"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM