note 90437 added to function.ereg

From: Date: Wed, 22 Apr 2009 10:33:49 +0000
Subject: note 90437 added to function.ereg
Groups: php.notes 
Request: Send a blank email to php-notes+get-153571@lists.php.net to get a copy of this message
Here a little clear and easy script that I wrote to validate an E-Mail Input. I tried to understand ereg, but the describtion on php.net did not help me, so I made some research and finally (think) that Im sure how to use ereg. The following function works for me well and allows an E-Mail to contain the following characters: "A-Z, a-z, 0-9, . , - , _ " function validateMail($mail) { if($mail !== "") { if(!ereg("^[A-Za-z0-9\.|-|_]* [@]{1}[A-Za-z0-9\.|-|_]*[.]{1}[a-z]{2,5}$", $mail)) { echo "wrong Input for E-Mail"; $mail =""; return $mail; } else { return $mail; } } } to make it clear: ^ means begin here (startpoint of ereg) $ means end here (endpoint of ereg) * stand for endless characters (I want A-Z, a-z, 0-9 and the other characters to apear from 0 to endless optional you can write {1,5} for min 1 times a character or max 5 times a characters instead of * {1,2} means min 1 time a character and max 2 times a character (optional you can write * intead of {1,2} {1} stand for max 1 time a character \ means from here special characters (like .-_$ and so on) | means OR ---- Server IP: 212.124.37.9 Probable Submitter: 194.45.150.17 ---- Manual Page -- http://www.php.net/manual/en/function.ereg.php Edit -- https://master.php.net/note/edit/90437 Del: integrated -- https://master.php.net/note/delete/90437/integrated Del: useless -- https://master.php.net/note/delete/90437/useless Del: bad code -- https://master.php.net/note/delete/90437/bad+code Del: spam -- https://master.php.net/note/delete/90437/spam Del: non-english -- https://master.php.net/note/delete/90437/non-english Del: in docs -- https://master.php.net/note/delete/90437/in+docs Del: other reasons-- https://master.php.net/note/delete/90437 Reject -- https://master.php.net/note/reject/90437 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#153571) next »