【XenForo】在注册页面添加确认密码 密码限制

14 篇文章 0 订阅

后台---外观---模板列表---register_form

将密码部分的代码修改为下

<xf:comment>Spam catcher field</xf:comment>
<xf:if is="{{ rand(0, 2) == 1 }}">
<xf:textboxrow name="password" type="password" autocomplete="off" rowclass="formRow--limited"
label="{{ phrase('password') }}"
explain="{{ phrase('please_leave_this_field_blank') }}" />
</xf:if>

<xf:textboxrow name="{{ $regForm.getFieldName('password') }}" type="password" autocomplete="off"
label="{{ phrase('password') }}"
hint="{{ phrase('required') }}"
required="required" 
id="password"
οnkeyup="restrict()"
explain="<label style='margin-left:20px;' id='mimatishi'></label>"/>

<xf:macro template="register_macros" name="dob_row" />

<xf:macro template="register_macros" name="location_row"
arg-value="{$fields.location}" />

<xf:comment>Spam catcher field</xf:comment>
<xf:if is="{{ rand(0, 2) == 1 }}">
<xf:textboxrow name="confirm_password" type="password" autocomplete="off" rowclass="formRow--limited"
label="{{ phrase('confirm_password') }}"
explain="{{ phrase('please_leave_this_field_blank') }}" />
</xf:if>

<div>
<xf:textboxrow name="{{ $regForm.getFieldName('password') }}" type="password" autocomplete="off"
label="{{ phrase('confirm_password') }}"
hint="{{ phrase('required') }}"
required="required" 
id="confirm_password"
disabled="disabled"
οnkeyup="validate()" 
explain="<label style='margin-left:20px;' id='tishi'></label>"/>
</div>

并在最后面添加如下js代码:

function restrict(){
var password = document.getElementById("password").value;
var regxA =/[a-zA-Z]/;
var regx1 =/[1-9]/;
if(password.match(regxA)==null || password.match(regx1)==null || password == null || password.length < 8){
document.getElementById("mimatishi").innerHTML="<font color='red'>The password must contain numbers and letters and the length is more than 8</font>";
document.getElementById("js-signUpButton").disabled = true;

}else{
document.getElementById("mimatishi").innerHTML="<font color='green'>Correct password format</font>";
document.getElementById("js-signUpButton").disabled = false;
document.getElementById("confirm_password").disabled = false;
}
}
function validate() {
var pw1 = document.getElementById("password").value;
var pw2 = document.getElementById("confirm_password").value;
if(pw1 == pw2) {
document.getElementById("tishi").innerHTML="<font color='green'>The two passwords are the same</font>";
document.getElementById("js-signUpButton").disabled = false;
}
else {
document.getElementById("tishi").innerHTML="<font color='red'>The two passwords are not the same</font>";
document.getElementById("js-signUpButton").disabled = true;
}
}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值