如何更改或删除HTML5表单验证默认错误消息? [英] How can I change or remove HTML5 form validation default error messages?

查看:141
本文介绍了如何更改或删除HTML5表单验证默认错误消息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如我有一个 textfield 。该字段是必填字段,只需要数字,值的长度必须为10.当我尝试提交长度为5的值的表单时,会显示缺省错误消息:请匹配请求的格式 $ b

For example I have a textfield. The field is mandatory, only numbers are required and length of value must be 10. When I try to submit form with value which length is 5, the default error message appears: Please match the requested format

<input type="text" required="" pattern="[0-9]{10}" value="">




  1. 如何更改HTML 5表单验证错误的默认消息? li>
  2. 如果第一点可以完成,那么是否有办法创建一些属性文件并在该文件中设置自定义错误消息?


推荐答案

我发现Ankur答案有一个错误,我已修正了这个更正:

I found a bug on Ankur answer and I've fixed it with this correction:

 <input type="text" pattern="[a-zA-Z]+"
    oninvalid="setCustomValidity('Plz enter on Alphabets ')"
    onchange="try{setCustomValidity('')}catch(e){}" />

当您设置无效的输入数据,然后更正输入并发送表单时,会出现错误。
oops!你不能这样做。
我已经在firefox和chrome上测试过了。

The bug seen when you set an invalid input data, then correct the input and send the form. oops! you can't do this. I've tested it on firefox and chrome

这篇关于如何更改或删除HTML5表单验证默认错误消息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆