Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,154,577 members, 7,823,509 topics. Date: Friday, 10 May 2024 at 11:07 AM

[MOD] PHP Workouts-email Validation In Php Using Any Method. - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / [MOD] PHP Workouts-email Validation In Php Using Any Method. (1004 Views)

Hello House: Let's Do A Little PHP Using PDO / Adding Validation To Javascript Code / [MOD] PHP WORKOUTS - String Manipulation 1 (2) (3) (4)

(1) (Reply) (Go Down)

[MOD] PHP Workouts-email Validation In Php Using Any Method. by Kidstell: 12:58am On Aug 20, 2013
HAVE YOU EVER VALIDATED AN EMAIL?
HOW DID YOU DO IT?
There are thousands of techniques lets share both public and self developed methods.
As a means to keep the fire burning. I appeal to programmers to see this thread as a repository that you can always come back to check.
RULES-
;-> NO MORE RULES
I thinks its time we talked about which is poor and the possible flaws.
Re: [MOD] PHP Workouts-email Validation In Php Using Any Method. by ToyinDipo(m): 8:20am On Aug 20, 2013
@Pattern(regexp="[a-z0-9!#$%&’*+/=?^_‘{|}~-]+(?:\\."
+"[a-z0-9!#$%&’*+/=?^_‘{|}~-]+)*@"
+"(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?",
message="{invalid.email}"wink
private String email;

That was a validation method I once used with java. I got the regular expression from a java6 ee reference material

1 Like

Re: [MOD] PHP Workouts-email Validation In Php Using Any Method. by Kidstell: 8:43am On Aug 20, 2013
<?php
$email =$_POST['email'];
if(!filter_var($email, FILTER_VALIDATE_EMAIL))
{
echo "E-mail is not valid";
}
else
{
echo "E-mail is valid";
}
Re: [MOD] PHP Workouts-email Validation In Php Using Any Method. by ToyinDipo(m): 8:50am On Aug 20, 2013
I would say php made that easier than it is in java
Re: [MOD] PHP Workouts-email Validation In Php Using Any Method. by Kidstell: 11:47am On Aug 20, 2013
This method is so poor. And i doubt if php developers are willing to replace it for now. With this method brackets will still be allowed as input even quotes
Re: [MOD] PHP Workouts-email Validation In Php Using Any Method. by ToyinDipo(m): 7:31pm On Aug 20, 2013
That regular expression stuff is almost perfect if not perfect
Re: [MOD] PHP Workouts-email Validation In Php Using Any Method. by Deekaydadon(m): 6:10pm On Aug 21, 2013
You can always create a self developed one that checks for each symbol
Re: [MOD] PHP Workouts-email Validation In Php Using Any Method. by adewasco2k(m): 6:39pm On Aug 21, 2013
<?php
$email = $_POST['email'] ;
if(preg_match('/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/', $email))
{
echo "valid email"

}else
{
echo "invalid email" ;
}

2 Likes

Re: [MOD] PHP Workouts-email Validation In Php Using Any Method. by adewasco2k(m): 6:42pm On Aug 21, 2013
i use this mostly though

<?php
$email=$_POST['email'];
if(filter_var($email,FILTER_VALIDATE_EMAIL) === TRUE)
{
echo 'valid Email';
}
else
{
echo 'invalid email';
}
Re: [MOD] PHP Workouts-email Validation In Php Using Any Method. by Kidstell: 11:00am On Aug 23, 2013
ToyinDipo: @Pattern(regexp="[a-z0-9!#$%&’*+/=?^_‘{|}~-]+(?:\\."
+"[a-z0-9!#$%&’*+/=?^_‘{|}~-]+)*@"
+"(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?",
message="{invalid.email}"wink
private String email;

That was a validation method I once used with java. I got the regular expression from a java6 ee reference material
this raises a question of what is the proper set of allowed xters. This regular exp. Allows #* which i have never noticed in anyone's email address a good modification will be to simply reduce the accepted Xters. Also with php you will have to escape these special xters "^.[$()|*+?{/\" they have special meanings
Re: [MOD] PHP Workouts-email Validation In Php Using Any Method. by ToyinDipo(m): 7:56pm On Aug 23, 2013
Kidstell:
this raises a question of what is the proper set of allowed xters. This regular exp. Allows #* which i have never noticed in anyone's email address a good modification will be to simply reduce the accepted Xters. Also with php you will have to escape these special xters "^.[$()|*+?{/\" they have special meanings
It was experts that actually created that regexp. I believe they allowed the use of #* not because people use them, but because it is permissible. For instance in oracle, you can begin a variable name with _ or $, but conventionally it's not advisable, so people tend to begin variable names only with letters.

1 Like

Re: [MOD] PHP Workouts-email Validation In Php Using Any Method. by Kidstell: 3:23pm On Aug 24, 2013
Gradually our nairaland is getting better. Watch out for the next edition of PHP Workouts II- the topic was initially 9jerian phone number but its been solved already. Conclusively the best answer was given by Bro. Toyin Dipo using java (modified for php)
<?php
$email =$_POST['email'] ;
if(preg_match('/[a-z0-9!#\$%&’\*\+\/=\?\^_‘\{\|\}~-]+(?:\\."
\+"[a-z0-9!#\$%&’\*\+\/=\?\^_‘\{\|\}~-]+)*@"
+"(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?/', $email))
{
echo "valid email"
}else
{
echo "invalid email" ;
}
but to apply this solution in php be sure to escape the special characters try it post your correction because this moderator knows nothing about lamp or wamp. GOD BLESS MY BRETHREN.

1 Like

Re: [MOD] PHP Workouts-email Validation In Php Using Any Method. by ToyinDipo(m): 3:57pm On Aug 24, 2013
Kidstell: Gradually our nairaland is getting better. Watch out for the next edition of PHP Workouts II- the topic was initially 9jerian phone number but its been solved already. Conclusively the best answer was given by Bro. Toyin Dipo using java (modified for php)
<?php
$email =$_POST['email'] ;
if(preg_match('/[a-z0-9!#\$%&’\*\+\/=\?\^_‘\{\|\}~-]+(?:\\."
\+"[a-z0-9!#\$%&’\*\+\/=\?\^_‘\{\|\}~-]+)*@"
+"(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?/', $email))
{
echo "valid email"
}else
{
echo "invalid email" ;
}
but to apply this solution in php be sure to escape the special characters try it post your correction because this moderator knows nothing about lamp or wamp. GOD BLESS MY BRETHREN.
I'm humbled bro. Thanks.
Re: [MOD] PHP Workouts-email Validation In Php Using Any Method. by Kidstell: 12:03pm On Aug 27, 2013
Next is a topic that is very far from beginners plight but please quick around don't be discouraged. Make it your challenge as we all discuss sqlite3 php classes

(1) (Reply)

Website Review / Fact: How Do U Search On Google? / Bootstrap 4 Alpha Released

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 17
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.