Results 1 to 2 of 2

Thread: Problem with preg_match

  1. #1
    Join Date
    Aug 2006

    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:
    if (
    preg_match('/[1-9|a-z|A-Z]{6,14}/'$username)) {
    'Preg.. MATCH! $username is: ' $username '<br />';
    } else {
    '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
    PHP Code:
    if(preg_match('/^[a-z0-9]{6,14}$/i'$username)) { 
    "Well done....Consciousness to sarcasm in five seconds!" ~ Terry Pratchett, Night Watch

    How to Ask Questions the Smart Way (not affiliated with this site, but well worth reading)

    My Blog
    cwrBlog: simple, no-database PHP blogging framework

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