I have my website completely made in PHP. But I m stuck in the Email address validation. How can i do that with PHP More Info webmyne.com
<?php /** * Most corrected pattern for Email validation. * */ // Valid email echo preg_match('/^([a-z0-9])(([-a-z0-9._])*([a-z0-9]))* \@([a-z0-9])*(\.([a-z0-9])([-a-z0-9_-])([a-z0-9])+)*$/i' ,'09_az..AZ@host.dOMain.cOM'); // Invalid emails echo preg_match('/^([a-z0-9])(([-a-z0-9._])*([a-z0-9]))* \@([a-z0-9])*(\.([a-z0-9])([-a-z0-9_-])([a-z0-9])+)*$/i' ,'09_azAZ@ho...st...........domain.com'); echo preg_match('/^([a-z0-9])(([-a-z0-9._])*([a-z0-9]))* \@([a-z0-9])*(\.([a-z0-9])([-a-z0-9_-])([a-z0-9])+)*$/i' ,'09_azAZ@host.do@main.com'); ?> ---------------------------- Output: ---------------------------- 1 = valid 0 = invalid 0 = invalid for more details http://php.net/manual/en/function.preg-match.php
Developing a regex to match all valid email addresses or fail to match all invalid addresses may be impossible. Most can be matched, but probably not all. See a short list of URLs at the end of this note for more email address regex information. If most is good enough, then a complex or even a simple regular expression may be an acceptable compromise. The regular expression on this page may be the most complex email address validation regex ever devised. The regular expression contains 6343 characters. http://ex-parrot.com/~pdw/Mail-RFC822-Address.html Unless your project requires very strict checking, checking for invalid formats may be sufficient. Check for things like a missing @ or more than one @; a comma or semi-colon; and consecutive dots on the domain side of the @. Rejecting unless the address matches a certain format is likely to sooner or later reject a deliverable email address. As an aside, but related: The PHP preg_... functions do text processing with Perl-compatible regular expressions. The Internet is rich with juicy examples of tried and tested regular expression that can be ported from Perl to PHP with nary a change in the expression itself. It can be a fruitful avenue of research for sticky regex problems. URLs to some email address regex information: http://www.perl.com/CPAN/authors/Tom_Christiansen/scripts/ckaddr.gz (Download. A great example of email address validation.) http://docstore.mik.ua/orelly/linux/cgi/ch09_02.htm http://docstore.mik.ua/orelly/perl/cookbook/ch06_20.htm http://faq.perl.org/perlfaq9.html#How_do_I_check_a_val Will
My apologies for the lack of live links in the previous post. It seems the system doesn't trust me enough to publish links. Maybe you shouldn't trust me, either Will
Yeah, regex is pretty obscene, http://ex-parrot.com/~pdw/Mail-RFC822-Address.html is accurate enough.