Results 1 to 2 of 2

Thread: email validation

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Apr 2004
    Posts
    220

    email validation

    Hi, i was wondering if some1 could tell me the code to validate an email for incorrect charactors.
    I believe it is something like this but i am not to sure

    PHP Code:
      if (ereg('^[a-zA-Z0-9_\.\-]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$'$address))
        return 
    true;
      else 
        return 
    false;

    also how can i check for certain fields to be field in. i.e my form has 4 text fields ($name,$message,$email,$contact number)

    i want name,message and email to be filled in but contact number is optional. i cant figure out how to exclude contact number

    Thanks Adam

  2. #2
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906
    Your e-mail validation expression looks a little strict. The first part of the e-mail address before the @ sign can contain an number of other special characters. Users can enter the email address "[email protected]", which is clearly invalid but not "d^[email protected]", which is valid. You may want to look into more advanced checking of the e-mail address.

    This article describes some of them: http://coveryourasp.com/ValidateEmail.asp#Result1

    This gives a regular expression e-mail syntax checker. You can see just how many characters are valid in an e-mail address.

    http://www-2.cs.cmu.edu/~cache/email/

    Checking for optional fields is easy. You just need to check for an empty string in variable. For example the following checks if the field "contact" had anything entered:
    PHP Code:
    if ($_REQUEST['contact'] == ''
      
    /* nothing entered */
    else
      
    /* something was entered */ 
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width