provided my login page which contains password validation. I would like to add email address "thisisnotmyrealaddress@gmail.com"
to this code?
提供了包含密码验证的登录页面。我想在此代码中添加电子邮件地址“thisisnotmyrealaddress@gmail.com”?
I need help in setting my email address
我需要帮助设置我的电子邮件地址
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>
3 个解决方案
#1
0
add this before passsword field
在密码字段之前添加此内容
<td>Email</td>
<td><input type="text" id="email"></td>
In javascript add the following code
在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
function validateEmail($email) {
var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
return emailReg.test( $email );
}
and now to use this
现在要用它
if( !validateEmail(emailaddress)) { /* do stuff here */ }
#3
0
I tried the below given coding..It's working smoothly..
我尝试了下面给出的编码..它工作顺利..
<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>
#1
0
add this before passsword field
在密码字段之前添加此内容
<td>Email</td>
<td><input type="text" id="email"></td>
In javascript add the following code
在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
function validateEmail($email) {
var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
return emailReg.test( $email );
}
and now to use this
现在要用它
if( !validateEmail(emailaddress)) { /* do stuff here */ }
#3
0
I tried the below given coding..It's working smoothly..
我尝试了下面给出的编码..它工作顺利..
<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>