<html>
<head>
</head>
<body id="body">
<form action="https://maps.google.com/" name="f" method="get" id="exampleForm" onsubmit="return check()">
search:<input type="text" id="examplePass" name="q" >
<input type="submit" value="submit">
<br>
</form>
</body>
<script>
function check(){
var passwordRegex =/\-?\d+(\.\d+)?\,\-?\d+(\.\d+)?$/;
if(!passwordRegex.test(f.q.value)){
alert("!!!!!!");
f.q.value="";
return false;
}
}
/*
document.getElementById("exampleForm").onsubmit = function(){
var passwordRegex =/\-?\d+(\.\d+)?\,\-?\d+(\.\d+)?$/;
if(!passwordRegex.test(document.getElementById("examplePass").value)){
console.log("Regex didn't match");
return false;
var notify = document.getElementById("notify");
if(notify === null){
notify = document.createElement("p");
notify.textContent = "ERROR";
notify.id ="notify";
var body =document.getElementById("body");
body.appendChild(notify);
}
}
*/
</script>
</html>
沒有留言:
張貼留言