19

When the input does not match the pattern specified by the pattern attribute, Firefox simply says, "Please match the requested format", which is okay; however, when this validation fails Internet Explorer 10 displays "You must use this format:" in a tooltip with nothing else. This may be simple, but searching has not yielded me a clue as to how to supply text to the tooltip telling it the pattern that should be used.

Example below for a one to four digit number:

<input id="institution_threshold_days" type="text" placeholder="0-9999" pattern="^[0-9]{1,4}$" />
4

1 回答 1

28

尝试使用 title 属性来描述你想要它说的内容:

<input id="institution_threshold_days" type="text" placeholder="0-9999" pattern="^[0-9]{1,4}$" title="Please enter a number less than 10000." />

应该适用于所有主要浏览器...

来自微软

title 属性的内容既显示为字段的工具提示文本,又附加到通用模式不匹配错误消息中。

来自Mozilla

使用 title 属性来描述模式以帮助用户。

虽然我找不到官方文档,但它似乎也可以在 Chrome 中使用。

于 2013-08-19T18:46:28.353 回答