Validate an Email address of a text box

Hi there,

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...

Thanks a lot...


  • hi,

    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

  • I think I'll just try step 1

  • : I think I'll just try step 1

    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(".");
    alert("That is not a correct e-mail address!");
    return false;
    return true;

  • you might as well use a regular expression in PHP
    I use this one in our guestbook:
    {//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.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!