siabanie Posted August 1, 2011 Share Posted August 1, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/243477-php-validate-two-emails-if-match-or-not/ Share on other sites More sharing options...
Muddy_Funster Posted August 1, 2011 Share Posted August 1, 2011 That looks too much like JS for me. Quote Link to comment https://forums.phpfreaks.com/topic/243477-php-validate-two-emails-if-match-or-not/#findComment-1250200 Share on other sites More sharing options...
siabanie Posted August 1, 2011 Author Share Posted August 1, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/243477-php-validate-two-emails-if-match-or-not/#findComment-1250203 Share on other sites More sharing options...
ZulfadlyAshBurn Posted August 1, 2011 Share Posted August 1, 2011 Check This site. hope it helps Quote Link to comment https://forums.phpfreaks.com/topic/243477-php-validate-two-emails-if-match-or-not/#findComment-1250208 Share on other sites More sharing options...
siabanie Posted August 1, 2011 Author Share Posted August 1, 2011 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? Quote Link to comment https://forums.phpfreaks.com/topic/243477-php-validate-two-emails-if-match-or-not/#findComment-1250211 Share on other sites More sharing options...
ZulfadlyAshBurn Posted August 1, 2011 Share Posted August 1, 2011 you are using jQuery right? jQuery Validation Quote Link to comment https://forums.phpfreaks.com/topic/243477-php-validate-two-emails-if-match-or-not/#findComment-1250213 Share on other sites More sharing options...
siabanie Posted August 1, 2011 Author Share Posted August 1, 2011 you are using jQuery right? jQuery Validation Yes I am pretty new on this so I do not know much about it... Quote Link to comment https://forums.phpfreaks.com/topic/243477-php-validate-two-emails-if-match-or-not/#findComment-1250214 Share on other sites More sharing options...
ZulfadlyAshBurn Posted August 1, 2011 Share Posted August 1, 2011 maybe just stick to normal js if you would like. link Quote Link to comment https://forums.phpfreaks.com/topic/243477-php-validate-two-emails-if-match-or-not/#findComment-1250216 Share on other sites More sharing options...
siabanie Posted August 1, 2011 Author Share Posted August 1, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/243477-php-validate-two-emails-if-match-or-not/#findComment-1250219 Share on other sites More sharing options...
ZulfadlyAshBurn Posted August 1, 2011 Share Posted August 1, 2011 you can actually use part of the normal js code and implement it on the jQuery. Quote Link to comment https://forums.phpfreaks.com/topic/243477-php-validate-two-emails-if-match-or-not/#findComment-1250222 Share on other sites More sharing options...
siabanie Posted August 1, 2011 Author Share Posted August 1, 2011 you can actually use part of the normal js code and implement it on the jQuery. Hmmm? Can you show me how please? :confused: Quote Link to comment https://forums.phpfreaks.com/topic/243477-php-validate-two-emails-if-match-or-not/#findComment-1250224 Share on other sites More sharing options...
ZulfadlyAshBurn Posted August 1, 2011 Share Posted August 1, 2011 i would need to look into your code but for now, im rather busy studying for my prelims. Quote Link to comment https://forums.phpfreaks.com/topic/243477-php-validate-two-emails-if-match-or-not/#findComment-1250232 Share on other sites More sharing options...
siabanie Posted August 1, 2011 Author Share Posted August 1, 2011 i would need to look into your code but for now, im rather busy studying for my prelims. The snippets of the code is already on post#57 above - Anyway thanks and good luck with your prelims. Quote Link to comment https://forums.phpfreaks.com/topic/243477-php-validate-two-emails-if-match-or-not/#findComment-1250234 Share on other sites More sharing options...
ZulfadlyAshBurn Posted August 1, 2011 Share Posted August 1, 2011 Thanks Quote Link to comment https://forums.phpfreaks.com/topic/243477-php-validate-two-emails-if-match-or-not/#findComment-1250236 Share on other sites More sharing options...
spiderwell Posted August 1, 2011 Share Posted August 1, 2011 so is this resolved? ? if not can you show the current code state? Quote Link to comment https://forums.phpfreaks.com/topic/243477-php-validate-two-emails-if-match-or-not/#findComment-1250251 Share on other sites More sharing options...
ZulfadlyAshBurn Posted August 1, 2011 Share Posted August 1, 2011 so is this resolved? ? if not can you show the current code state? the code is at the top? Quote Link to comment https://forums.phpfreaks.com/topic/243477-php-validate-two-emails-if-match-or-not/#findComment-1250254 Share on other sites More sharing options...
siabanie Posted August 1, 2011 Author Share Posted August 1, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/243477-php-validate-two-emails-if-match-or-not/#findComment-1250256 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.