leone1234 0 Odesláno: 18. Duben, 2011 Share Odesláno: 18. Duben, 2011 Validácia emailovej adresy Zisti, či ma zadaný email správny tvar. Ak ma email správny formát, funkcia vracia TRUE, v opacnom pripade FALSE. <?php function isValidEmail($email) { $regexp1 = "^[a-z0-9_\+-]+(\.[a-z0-9_\+-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*\.([a-z]{2,4})$"; $regexp2 = "^[a-z0-9,!#\$%&'\*\+/=\?\^_`\{\|}~-]+(\.[a-z0-9,!#\$%&'\*\+/=\?\^_`\{\|}~-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*\.([a-z]{2,})$"; //skontroluje dovolenú dĺžku jednotlivých časti emailovej adresy if(!ereg("^[^@]{1,64}@[^@]{1,255}$",$email)) { return false; } return (eregi($regexp1,$email) || eregi($regexp2,$email)) ? true : false; } ?> Príklad použitia: $email = "nieč[email protected]"; if(isValidEmail($email)) { echo "Emailova adresa ma spravny tvar."; } else { echo "Chybna emailova adresa!"; } Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now