Jump to content

PHP Validate Two Emails If Match or Not?


siabanie

Recommended Posts

Hi all,

 

I need some favour about checking if the first email that user entered was match with the confirmation email otherwise show an error message: "The email address is not match" or something like that..

 

Here is the snippets of error checking for email and email_1 if it is empty - but I don't know how I can add another validate if both of the emails match or not? And do I need to add them in PHP code?

 

Please suggest, any help would be highly appreciated.

 

..
..
$('[name=email]').parent().removeClass('error');
      if($('[name=email]').val()=="" || $('[name=email_1]').val()==""){
        error_num++;
        error_mesg += "Please enter E-mail\n";
        $('[name=email]').parent().addClass('error');
        //if($('[name=tel_p2]').val()=="" ) 
      }
..

 

Form HTML + PHP

..
<tr>
        <td bgcolor="#F6F6F6">E-mail<span class="green"> *</span></td>
        <td colspan="2" bgcolor="#FFFFFF"><input name="email" type="text" size="40" value="<?php echo $_SESSION["email"];?>" />
 <td>
      </tr>
  <tr>
        <td bgcolor="#F6F6F6">E-mail Confirmation<span class="green"> *</span></td>
        <td colspan="2" bgcolor="#FFFFFF"><input name="email" type="text" size="40" value="<?php echo $_SESSION["email"];?>" />
 <td>
      </tr>
...

 

Thanks alot.

Link to comment
Share on other sites

That looks too much like JS for me.

 

Sorry yes I mean in JS but if you could show me in PHP would be great as I heard that PHP is much secure than JS? - I would be grateful if you could assist me how I can implemented it in JS please.

 

Thanks.

Link to comment
Share on other sites

Check This site. hope it helps

 

Thanks ZulfadlyAshBurn,

 

But what I need is just JS to determine if both email addresses are match or not. I do not need the function at the moment just want both of them match otherwise error message:

 

I tried to do something like this:

//If first email address is empty show error msg
  $('[name=email]').parent().removeClass('error');
      if($('[name=email]').val()==""){
        error_num++;
        error_mesg += "E-mail。\n";
        $('[name=email]').parent().addClass('error');
      }
  
//If second email address is empty show error msg
  $('[name=email_1]').parent().removeClass('error');
      if($('[name=email_1]').val()==""){
        error_num++;
        error_mesg += "Please confirm your email\n";
        $('[name=email_1]').parent().addClass('error');
      }

//If first email and second email address not match show error msg	  
    $('[name=email_1]').parent().removeClass('error');
      if($('[email != email_1]').val()){
        error_num++;
        error_mesg += "E-mail not match\n";
        $('[name=email_1]').parent().addClass('error');
      }

 

The first and second JS (when fields are empty) are giving me an error which is correct but the third one did not work.

 

I am not exactly sure how it should be written. I tried I need to add something like this:

$('[name=email]').parent().removeClass('error') && $('[name=email_1]').parent().removeClass('error');
   if($('[name=email != name=email_1]').val()){
        error_num++;
        error_mesg += "E-mail not match\n";
        $('[name=email]').parent().addClass('error') && $('[name=email_1]').parent().addClass('error');
      }

 

...but it did not work.....anyone please?

Link to comment
Share on other sites

so is this resolved? ? if not can you show the current code state?

 

No it is not resolved spiderwell, yes the code at the top but here it is again:

 

Snippets of the form fields

<?php
session_start();

$_SESSION['email'] = '';
  $_SESSION['email_1'] = '';
..
..
?>
..
..
<tr>
        <td bgcolor="#F6F6F6">E-mail<span class="green"> *</span></td>
        <td colspan="2" bgcolor="#FFFFFF"><input name="email" type="text" size="40" value="<?php echo $_SESSION["email"];?>" />
 <td>
      </tr>
  <tr>
        <td bgcolor="#F6F6F6">Retype E-mail<span class="green"> *</span></td>
        <td colspan="2" bgcolor="#FFFFFF"><input name="email_1" type="text" size="40" value="<?php echo $_SESSION["email_1"];?>" />
 <td>
      </tr>
..
..

 

//If first email address is empty show error msg -  Work fine.
  $('[name=email]').parent().removeClass('error');
      if($('[name=email]').val()==""){
        error_num++;
        error_mesg += "E-mail。\n";
        $('[name=email]').parent().addClass('error');
      }
  
//If second email address is empty show error msg - Work fine.
  $('[name=email_1]').parent().removeClass('error');
      if($('[name=email_1]').val()==""){
        error_num++;
        error_mesg += "Please confirm your email\n";
        $('[name=email_1]').parent().addClass('error');
      }

//If the first email and the second email address NOT match show error msg	  - NOT working yet
    $('[name=email_1]').parent().removeClass('error');
      if($('[email != email_1]').val()){
        error_num++;
        error_mesg += "E-mail not match\n";
        $('[name=email_1]').parent().addClass('error');
      }

 

So I thought I tried this again but still not working:

$('[name=email]').parent().removeClass('error') && $('[name=email_1]').parent().removeClass('error');
   if($('[name=email != name=email_1]').val()){
        error_num++;
        error_mesg += "E-mail not match\n";
        $('[name=email]').parent().addClass('error') && $('[name=email_1]').parent().addClass('error');
      }

 

Maybe the way I coding isn't correct or something..? Any idea?

Thanks.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.