例如,我有textfield
分.此字段为必填字段,只需要数字,值长度必须为10.当我try 提交长度为5的值的表单时,默认错误消息显示:Please match the requested format
<input type="text" required="" pattern="[0-9]{10}" value="">
- 如何更改HTML 5表单验证错误默认消息?
- 如果第一点可以做到,那么有没有办法创建一些属性文件,并在这些文件中设置自定义错误消息?
例如,我有textfield
分.此字段为必填字段,只需要数字,值长度必须为10.当我try 提交长度为5的值的表单时,默认错误消息显示:Please match the requested format
<input type="text" required="" pattern="[0-9]{10}" value="">
这是JavaScript解决方案:
<input type="text"
pattern="[a-zA-Z]+"
oninvalid="setCustomValidity('Please enter Alphabets.')"
onchange="try{setCustomValidity('')}catch(e){}" />
"onchange"事件需要在设置无效输入数据时,更正输入并再次发送表单.
But for Modern Browsers:
现代浏览器不需要任何JavaScript进行验证.
<input type="text"
pattern="[a-zA-Z]+"
title="Please enter Alphabets."
required="" />