js 正則表達式驗證密碼(6位以上數字字母特殊符號組合)
function checkPsw(password){
//密碼必須是數字、字母、特殊符號混合,且大於6位
var patrn = /^(?=.*[a-zA-Z])(?=.*\d)(?=.*[#@!~%^&*.])[a-zA-Z\d#@!~%^&*.]{6,}$/;
if (!patrn.exec(password)){
return false;
}else{
return true;
}
}
php 正則驗證密碼
<?php
function checkPassword($password){
//密碼必須是數字字母特殊符號混合,且大於6位
if(!preg_match('/(?=.*[a-zA-Z])(?=.*\d)(?=.*[#@!~%^&*.])[a-zA-Z\d#@!~%^&*.]{6,}/i', $password)){
return false;
}else{
return true;
}
}