Results 1 to 2 of 2

Thread: Regular Expressions in PHP

  1. #1

    Thread Starter
    Hyperactive Member tomcatexodus's Avatar
    Join Date
    Feb 2001
    Posts
    372

    Regular Expressions in PHP

    I suppose this could fall into any language category that utilizes regular expressions;

    Anyways, I'm trying to do a simple test on a string (a username) to ensure that it only contains 6 to 20 alphanumeric characters.

    My pattern line is as follows:

    Code:
    $pattern = "/[A-Za-z0-9]{6,20}/";
    Now, it works sort of, but if someone were to enter a string such as this:

    Code:
    abcdef&
    It doesn't catch the ampersand. It only seems to care about the first 6 characters being alphanumeric (It happens with &, *, %, spaces, etc.) Now, I'm new with regex, but I can't seem to understand what I'm missing. Anyone?
    IWS

  2. #2
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Regular Expressions in PHP

    Use

    ^...$

    to match the entire line.

    Replace ... with the pattern you have now between the / characters.

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