后台---外观---模板列表---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;
}
}