javascript - 如何使用 html/java 确保电子邮件和确认电子邮件输入匹配
问题描述
我是新来的,所以请放轻松。
目前在shopify表单上我已经编辑了注册,以便它要求电子邮件,然后也是一个确认电子邮件框。在客户提交表单之前,我如何确保两个框都匹配,如果不匹配,它希望它声明“电子邮件地址不匹配”。我相信这将通过 javascript 但不确定。
这就是我的代码查找 2 个框的方式。
<div class="Form__Item">
<input type="email" class="Form__Input" name="customer[email]" aria-label="{{ 'customer.register.email' | t }}" placeholder="{{ 'customer.register.email' | t }}" required="required">
<label class="Form__FloatingLabel">{{ 'customer.register.email' | t }}</label>
</div>
<div class="Form__Item">
<input type="email" class="Form__Input" name="customer[confirm_email]" aria-label="{{ 'customer.register.confirm_email' | t }}" placeholder="{{ 'customer.register.confirm_email' | t }}" required="required">
<label class="Form__FloatingLabel">{{ 'customer.register.confirm_email' | t }}</label>
</div>
<div class="Form__Item">
<input type="password" class="Form__Input" name="customer[password]" aria-label="{{ 'customer.register.password' | t }}" placeholder="{{ 'customer.register.password' | t }}" required="required">
<label class="Form__FloatingLabel">{{ 'customer.register.password' | t }}</label>
</div>
<button type="submit" class="Form__Submit Button Button--primary Button--full">{{ 'customer.register.submit' | t }}</button>
{%- endform -%}
</div>
提前感谢您的帮助
解决方案
使用HTML5,您可以检查Required、minLenght、MaxLength等输入的常见验证...甚至是输入数据
的模式,在这种情况下,您必须使用javascript 并更好地使用JQuery
示例:
<input type="text" id="id1" />
<input type="text" id="id2" />
$('input').blur(function() {
if ($('#id1').attr('value') == $('#id2').attr('value')) {
alert('Same Value');
return false;
} else { return true; }
});
推荐阅读
- android - 开始构建 Android ROM
- swift - macOS App Development 和 Release 版本之间的不同行为
- algorithm - 迪杰斯特拉算法。到达被其他节点从当前节点“切断”的未访问节点
- python - 不明白为什么我在 python 脚本中收到此错误
- r - 使用 dplyr/基函数 R 在组内随机选择观察值
- java - 为什么要使用@Query(“”)来操作Elasticsearch并报错(org.elasticsearch.common.ParsingException: no [query] registered for [query])
- tensorflow2.0 - 不规则张量的串联会引发值错误
- javascript - 在 React 中处理对一个巨大的 10 列表进行排序的最佳方法?
- c# - 如何使用 ToShortDateString 拼出月份?
- python - ValueError:检查目标时出错:预期dense_3的形状为(1,)但得到的数组形状为(2,)keras