<head>
</head>
<body id="body">
<form action="javascript:void(0);" id="exampleForm2">
<input id="examplePass" />
<input type="submit" />
</form>
</body>
<script>
document.getElementById("exampleForm2").onsubmit = function() {
var passwordRegex = /-?\d+(\.\d+)?\,\-?\d+(\.\d+)?$/; //此行應為正確
if(!passwordRegex.test(document.getElementById("examplePass").value)){
console.log("Regex didn't match");
var notify = document.getElementById("notify");
if(notify === null) {
notify = document.createElement("p");
notify.textContent = "此輸入不符合'整數或小數,逗號,整數或小數'格式"
notify.id = "notify";
var body = document.getElementById("body");
body.appendChild(notify);
}
}
};
</script>
</html>
判斷此輸入是否符合此輸入不符合"整數或小數,逗號,整數或小數"格式
沒有留言:
張貼留言