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
https://forums.phpfreaks.com/topic/243477-php-validate-two-emails-if-match-or-not/
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?

maybe just stick to normal js if you would like. link

 

Yes would be good idea but the problem is; the code has been already implemented in jQuery for error messages and by doing in JS mean I have to change everything and adding the new functions etc.  :confused:

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.