我可以检查空字段,但如何检查有效的电子邮件检查正则表达式?这是我到目前为止所拥有的
<script>
function validateForm()
{
var x=document.forms["myForm"]["fname"].value;
if (x==null || x=="")
{
alert("First name must be filled out");
return false;
}
var y=document.forms["myForm"]["email"].value;
if (y==null || y=="")
{
alert("email must be filled out");
return false;
}
}
</script>
</head>
<body>
<form name="myForm" action="demo_form.asp" onsubmit="return validateForm()" method="post">
First name: <input type="text" name="fname"><br>
email: <input type="text" name="email">
<br><br>
<input type="submit" value="Submit">
</form>