简体   繁体   English

HTML5验证和字段比较

[英]HTML5 validation and field comparison

Is there currently any way to make a comparison check between 2 fields to check either that they match or do not match in HTML5 validation? 目前有没有办法在两个字段之间进行比较检查,以检查它们是否匹配或在HTML5验证中不匹配? Or would you have to write your own Javascript to do it? 或者你必须编写自己的Javascript来做到这一点?

使用HTML5无法完成那种检查。

Not exactly with HTML5 validation but a little JavaScript can resolve the issue, following is a general example regarding your question: 不完全是HTML5验证,但有一点JavaScript可以解决问题,以下是关于您的问题的一般示例:

<form method="post" enctype="multipart/form-data" action="Your_Action_Page.php">
<p>Password:</p>
<input name="password" required="required" type="password" id="password" />
<p>Confirm Password:
</p>
<input name="password_confirm" required="required" type="password" id="password_confirm" oninput="check(this)"  />
<script language='javascript' type='text/javascript'>
function check(input) {
if (input.value != document.getElementById('password').value) {
input.setCustomValidity('Password Must be Matching.');
} else {
// input is valid -- reset the error message
input.setCustomValidity('');
}
}
</script>
<br /><br />
<input type="submit" />
</form>

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

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