提供了包含密码验证的登录页面。我想在此代码中添加电子邮件地址"thisisnotmyrealaddress@gmail.com"
吗?
我需要帮助设置我的电子邮件地址
的login.html
<html>
<head>
<script type="text/javascript">
function validation()
{
var a = document.form.pass.value;
var valid = true;
if(a=="")
{
valid = false;
alert("Please Enter Your Password");
}
else if (a != 'notmyrealpassword') {
valid = false;
alert("Your Password is wrong");
}
if (valid) {
alert('form submitted');
}
else {
document.form.pass.focus();
return false;
}
}
</script>
</head>
<body>
<form name="form" method="post" onsubmit="return validation()" action="class_info.html">
<tr>
<td> password:</td>
<td><input type="text" name="pass"></td>
</tr>
<tr>
<td></td>
<td><input type="submit" name="sub" value="Submit"></td>
</tr>
</form>
</body>
</html>
答案 0 :(得分:0)
function validateEmail($email) {
var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
return emailReg.test( $email );
}
现在要使用这个
if( !validateEmail(emailaddress)) { /* do stuff here */ }
答案 1 :(得分:0)
在密码字段
之前添加此内容 <td>Email</td>
<td><input type="text" id="email"></td>
在javascript中添加以下代码
var b = document.getElementById('email').value;
var validate=/^[A-Za-z0-9#]{0,50}\@[A-Za-z]{0,10}\.[a-z]{0,3}$/g;
if(b!='')
{
if(!validate.test(b)){
alert("Enter the Valid Email");
return false;
}
}else{alert ("Enter Email");}
答案 2 :(得分:0)
我尝试了下面给出的编码..它运作顺利..
<html>
<head>
<script type="text/javascript">
function validation()
{
var b = document.form.pass.value;
var a = document.form.mail.value;
var valid = true;
if(a=="")
{
valid = false;
alert("Please Enter Your email");
}
else if (a != '303nishanth@gmail.com') {
valid = false;
alert("Your email is wrong");
}
if (valid) {
}
else {
document.form.mail.focus();
return false;
}
if(b=="")
{
valid = false;
alert("Please Enter Your password");
}
else if (b != 'password123') {
valid = false;
alert("Your password is wrong");
}
if (valid) {
alert('Email & password matches');
}
else {
document.form.pass.focus();
return false;
}
}
</script>
</head>
<body>
<form name="form" method="post" onsubmit="return validation()" action="class_info.html">
<tr>
<td> email:</td>
<td><input type="text" name="mail"></td>
</tr>
<tr>
<td> Password:</td>
<td><input type="password" name="pass"></td>
</tr>
<tr>
<td></td>
<td><input type="submit" name="sub" value="Submit"></td>
</tr>
</form>
</body>
</html>