I need to validate an email address from a text box and I dont' know if there's some function that does that or I have to create one. if you know it or have an idea, it is welcome...
in first step I would check the chars, if there is no @ or no . - the eMail adress is not valid.
The second step is much more tricky - just send a testmail to this user with sender-adress xyz. Now you create a cronjob that receives the mails for the mail adress xyz and checks for mailer daemon messages, if there are any for some adresses - they will be marked as not valid eMail-adresses.
I suggest, just using step 1 is much more easier
best regards,
sebastian mohrenstecher executive secretary net::allies
Personally I'd perform the validation on the client-side instead of on the server. Here's some Javascript I've used to achieve this:
var spos=emailStr.indexOf("@); /*emailStr is the e-mail address*/ var rspos=emailStr.lastIndexOf("@); var rppos=emailStr.lastIndexOf("."); if((spos<1)||((rppos-rspos)<2)) { alert("That is not a correct e-mail address!"); return false; }else{ return true; }
you might as well use a regular expression in PHP I use this one in our guestbook: if(ereg("^[_a-zA-Z0-9-]+(.[_a-zA-Z0-9-]+)*@([a-zA-Z0-9-]+.)+([a-zA-Z]{2,4})$",$email)) {//email-adress is correct - continue...}
Doing the validation with Javascript does not obviate the need to do it Server side with PHP. Remember, you never trust user supplied data. It is very easy to bypass any validation performed by Javascript and submit munged data. Javascript validation is a convenience only, to simplify data correction from the users standpoint.
Comments
in first step I would check the chars, if there is no @ or no . - the eMail adress is not valid.
The second step is much more tricky - just send a testmail to this user with sender-adress xyz. Now you create a cronjob that receives the mails for the mail adress xyz and checks for mailer daemon messages, if there are any for some adresses - they will be marked as not valid eMail-adresses.
I suggest, just using step 1 is much more easier
best regards,
sebastian mohrenstecher
executive secretary
net::allies
www.net-allies.de
info@net-allies.de
:
:
Personally I'd perform the validation on the client-side instead of on the server.
Here's some Javascript I've used to achieve this:
var spos=emailStr.indexOf("@); /*emailStr is the e-mail address*/
var rspos=emailStr.lastIndexOf("@);
var rppos=emailStr.lastIndexOf(".");
if((spos<1)||((rppos-rspos)<2))
{
alert("That is not a correct e-mail address!");
return false;
}else{
return true;
}
I use this one in our guestbook:
if(ereg("^[_a-zA-Z0-9-]+(.[_a-zA-Z0-9-]+)*@([a-zA-Z0-9-]+.)+([a-zA-Z]{2,4})$",$email))
{//email-adress is correct - continue...}