<!DOCTYPE html>
<html>
<head>
<title>test</title>
</head>
<script type="text/javascript">
function check(){
var value = document.getElementById("pwd").value;
var reg=new RegExp('^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{6,18}$');//位數自行調整
if(reg.test(value)){
alert("徹底正確")
return true;
}else{
alert("密碼不合法")
return false;
}
}
</script>
<body>
<input type="text" name="password" id="pwd">
<button onClick=check()>Test</button>
</body>
</html>javascript