SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Thread: pregmatch help

  1. #1
    SitePoint Guru adammc's Avatar
    Join Date
    Aug 2004
    Location
    Cairns, Australia
    Posts
    762
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question pregmatch help

    Hi guys,

    I would like to validate a name field on a submitted form to allow:
    letters, spaces, apostrophes and hyphens

    this is causing my script to halt:

    PHP Code:
    // Validate the name - abc's, spaces, periods and apostrophes only
    if(empty($authors_name)){
        
    $error .= "Please enter your name.";
        }
        (!
    preg_match('/^[a-zA-Z/\'/\.-]{2,30}$/',$authors_name)){ 
            
    $error .= "Your name contains invalid characters.";
            } 

  2. #2
    @php.net Salathe's Avatar
    Join Date
    Dec 2004
    Location
    Edinburgh
    Posts
    1,396
    Mentioned
    61 Post(s)
    Tagged
    0 Thread(s)
    There is no "if" at the beginning of the line containing the preg_match() function call, and the regular expression would be broken even if that were present.

    P.S. By "causing my script to halt" you really mean, "causing my script to halt with a lovely, helpful error message which points me directly to the problem", right?
    Salathe
    Software Developer and PHP Manual Author.


Bookmarks

Posting Permissions

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