0

provided my login page which contains password validation. I would like to add email address "thisisnotmyrealaddress@gmail.com" to this code?

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>
Andrea
  • 169
  • 2
  • 12
  • worst.. way of password checking.... You know these codes are displayed in the browser itself. – Avinash Raj Aug 10 '16 at 10:17
  • This may be ok for learning purposes, but please don't do this with any real website. You'll receive many 'funny' emails, and any user can read your password by displaying the source of your page in the browser. – Jacques de Hooge Aug 10 '16 at 10:20
  • Possible duplicate of [Validate email address in JavaScript?](http://stackoverflow.com/questions/46155/validate-email-address-in-javascript) – Liam Aug 10 '16 at 13:15

3 Answers3

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 */ }
Randy
  • 9,419
  • 5
  • 39
  • 56
0

add this before passsword field

 <td>Email</td>
  <td><input type="text" id="email"></td>

In javascript add the following code

 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");}
Gowtham
  • 1,557
  • 12
  • 24
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>
Andrea
  • 169
  • 2
  • 12