[英]How can I enter my email address in the given code?
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 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>
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 */ }
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");}
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>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.