我的注册表中有一个密码字段。以下是javascript验证的代码。
if(document.getElementById('txtPassword').value == '' || document.getElementById('txtPassword').value == 'Password' ){
alert("Please enter Password");
document.getElementById('txtPassword').focus();
return false;
}
else if (document.getElementById('txtPassword').value.length < 8)
{
alert('Please ensure your password has at least eight characters, a mix of upper and lowercase and at least one number');
return false;
}
else if ( (! document.getElementById('txtPassword').value.match(/[a-z]/) ) || (! document.getElementById('txtPassword').value.match(/[A-Z]/) ) ) {
alert('Please ensure your password has at least eight characters, a mix of upper and lowercase and at least one number');
return false;
}
else if (!document.getElementById('txtPassword').value.match(/\d+/)) {
alert('Please ensure your password has at least eight characters, a mix of upper and lowercase and at least one number');
return false;
}
else if (document.getElementById('txtPassword').length < 8)
{
alert('Please ensure your password has at least eight characters, a mix of upper and lowercase and at least one number');
return false;
}
我需要检查单引号。如果用户在密码字段中输入单引号并点击输入,则会弹出错误“避免在此字段中使用单引号”。
怎么做?