Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
HTML5 提供了使用正则表达式的 JavaScript 验证的替代方案。但我想在单个输入字段上添加多个验证,并据此显示消息。
例如。
<input type=passowrd name=passowrd/>
此处密码字段应包含以下验证消息。
恐怕它不能单独使用 HTML(不,甚至 HTML5)。
您必须使用 JavaScript 来完成任务。
约束验证仅针对每个输入字段的一条错误消息而设计。解决此问题的一种方法是连接验证消息。
password.setCustomValidity(password.validationMessage + ' At least one capital letter');
缺点是您不能附加 html,因此所有消息都将内联放置。