|
-
Dec 1st, 2009, 01:50 AM
#1
Thread Starter
Hyperactive Member
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:
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?
-
Dec 1st, 2009, 07:24 AM
#2
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|