Uldis Posted July 24, 2010 Report Share Posted July 24, 2010 (edited) Varbūt kādam noderēs - skripts pārbauda vai epasta forma ir korekta un vai norādītais hosts ir īsts, piem., andris@inboxx.lv atgriezīs false vērtību. <?php function check_email($mail_address) { $pattern = "/^[\w-]+(\.[\w-]+)*@"; $pattern .= "([0-9a-z][0-9a-z-]*[0-9a-z]\.)+([a-z]{2,4})$/i"; if (preg_match($pattern, $mail_address)) { $parts = explode("@", $mail_address); if (checkdnsrr($parts[1], "MX")){ echo "The e-mail address is valid."; // return true; } else { echo "The e-mail host is not valid."; // return false; } } else { echo "The e-mail address contains invalid charcters."; // return false; } } check_email("INFO@google.co.uk"); ?> Edited July 24, 2010 by Uldis Quote Link to comment Share on other sites More sharing options...
Klez Posted July 24, 2010 Report Share Posted July 24, 2010 uz šādu epasta adresi būs false. events@aimm.museum http://aimm.museum/contact.asp Quote Link to comment Share on other sites More sharing options...
marrtins Posted July 24, 2010 Report Share Posted July 24, 2010 Kā arī uz part1@part2@gmail.com Quote Link to comment Share on other sites More sharing options...
daGrevis Posted July 24, 2010 Report Share Posted July 24, 2010 Kāds varētu to skriptu nedaudz noslīpēt tā, lai ietu ar visiem variantiem. =) /^[a-z0-9!#$%&\'*+?^_`{|}~-]+(?:\.[a-z0-9!#$%&\'*+?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$/ Tas it kā der regex'am. =) Quote Link to comment Share on other sites More sharing options...
p4F Posted July 24, 2010 Report Share Posted July 24, 2010 http://lv.php.net/filter_var Quote Link to comment Share on other sites More sharing options...
sheps Posted July 25, 2010 Report Share Posted July 25, 2010 (edited) /^([_A-z0-9-]+((\.|\+)[_A-z0-9-]+)*@)+[A-z0-9-]+(\.[A-z0-9-]+)*(\.[A-z]{2,6})$/ ja veic šādas nelielas izmaiņas tad strādās gan ar diviem @ un arī .museum bet personiigi es neljauju lietot divus @ pārāk maz tādu epastu, lai taisiitu izņēmumus.. :)) BEZ diviem vai vairāk @ /^[_A-z0-9-]+((\.|\+)[_A-z0-9-]+)*@[A-z0-9-]+(\.[A-z0-9-]+)*(\.[A-z]{2,6})$/ priekā :) Edited July 25, 2010 by sheps Quote Link to comment Share on other sites More sharing options...
Klez Posted July 25, 2010 Report Share Posted July 25, 2010 es personigi neesmu redzejis mailu ar diviem @ pec standarta saprotu ka valids mails ir "user@abc"@domain.lv RFC invalid e-mail addresses * Abc.example.com (character @ is missing) * A@b@c@example.com (only one @ is allowed outside quotations marks) * ()[]\;:,<>@example.com (none of the characters before the @ in this example are allowed outside quotation marks) Quote Link to comment Share on other sites More sharing options...
Maaren Posted July 26, 2010 Report Share Posted July 26, 2010 filter_var($mail, FILTER_VALIDATE_EMAIL) kas vainas šim? Quote Link to comment Share on other sites More sharing options...
briedis Posted July 26, 2010 Report Share Posted July 26, 2010 filter_var($mail, FILTER_VALIDATE_EMAIL) kas vainas šim? +1, nav ko izgudrot riteni, ja php jau defaultā piedāvā šādu iespēju... Pašam tikai lielāka iespēja nokļūdīties... Quote Link to comment Share on other sites More sharing options...
rATRIJS Posted July 26, 2010 Report Share Posted July 26, 2010 (edited) Ja godiigi, tad tas filter_var nav iipashi labs, jo vinjapraat ratrijs@localhost ir valiids epasts, kas noteiktos gadiijumos ir tiesa, tachu ne vienmeer :D Edited July 26, 2010 by rATRIJS Quote Link to comment Share on other sites More sharing options...
bubu Posted July 26, 2010 Report Share Posted July 26, 2010 Noteiktos gadījumos e-pasts abrakadarba@lieli.laachi.lv arī ir patiess (tad kad tāds serveris ir uzstādīts un strādā), bet ne vienmēr. Ko tavuprāt darīt ar tādu e-pasta adresi? Vai tikpat labi i.like.billy.gates@inbox.lv ? Kādos gadījumos tāds e-pasts ir valīds tavuprāt? E-pasta validatoram jāpārbauda e-pasta stringa sintakses valīdums (RFCxyz kura tur atbilstība), nevis vai uz konkrētā hosta ir serveris/akkounts. To lai dara e-pasta sūtīšanas programma. Quote Link to comment Share on other sites More sharing options...
indoom Posted July 26, 2010 Report Share Posted July 26, 2010 filter_var var arī nebūt pieejams (PHP 5 >= 5.2.0). Ir (populāri) hostingi, kas vēl tup zem 5.2 Quote Link to comment Share on other sites More sharing options...
Maaren Posted July 30, 2010 Report Share Posted July 30, 2010 (edited) Ja godiigi, tad tas filter_var nav iipashi labs, jo vinjapraat ratrijs@localhost ir valiids epasts, kas noteiktos gadiijumos ir tiesa, tachu ne vienmeer :D if( filter_var($mail, FILTER_VALIDATE_EMAIL) && strrchr($mail, '@') != '@localhost' ) kaut kā tā ;) Jebkurā gadījumā labāk nekā rakstīt garu funkciju. Edited July 30, 2010 by Maaren Quote Link to comment Share on other sites More sharing options...
Uldis Posted August 1, 2010 Author Report Share Posted August 1, 2010 Galvenā doma jau bija tā, ka skripts pārbauda hosta esamību. Protams validātors ir arī iebūvēts,bet ne vienmēr ar to pietiek un 1:10000 gadījumiem vajadzēs arī pārbaudīt vai epasts atbild. Quote Link to comment 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.