www.webdeveloper.com
Results 1 to 2 of 2

Thread: Problem with preg_match

  1. #1
    Join Date
    Aug 2006
    Posts
    255

    Problem with preg_match

    Hello all,

    I am trying to ensure that a given username consists of alpha-numeric characters only. Here's the code:
    PHP Code:
    <?php
    $username 
    "madmax's";
    if (
    preg_match('/[1-9|a-z|A-Z]{6,14}/'$username)) {
        echo 
    'Preg.. MATCH! $username is: ' $username '<br />';
    } else {
        echo 
    'No preg_match. Username may consist of alpha-numeric characters only';
    }
    ?>
    And here's the output to the browser:
    ---
    Preg.. MATCH! $username is: madmax's
    ---

    What's wrong with my code? The apostrophe in madmax's should have meant the pregmatch failed..

  2. #2
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,174
    PHP Code:
    if(preg_match('/^[a-z0-9]{6,14}$/i'$username)) { 
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles