js求正則表達式?
代碼示例:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<form>
<input type="text" name="fname" id="fname"/>
<input type="button" value="Submit" id="submit"/>
</form>
<script>
window.onload=function(){
/*js 求正則表達式: 8-20位 必須包涵大寫字母,小寫字母,數字,特殊字符, 必須包涵哈.*/
document.getElementById("submit").onclick=function(){
var fname=document.getElementById("fname").value;
var pattern=/[A-Z]+[a-z]+[0-9]+[^A-Za-z0-9]+/g;
alert(pattern.test(fname));
if(fname.length<8 || fname.length>20){
alert("長度必須是8-20位");
}
}
}
</script>
</body>
</html>