[SOLVED] need help with a regular expression

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
escanive
Forum Newbie
Posts: 2
Joined: Mon Sep 22, 2008 2:32 am

[SOLVED] need help with a regular expression

Post by escanive »

Hi,

I'm currently creating my own forum "from skratch" (reason: I want features that other free forum solutions can't offer me, and don't need all of their features).

I'm now working on the "generate new password" part and I need a little help to use regular expressions to check that the validation code is in the correct format (in order to protect the forum from SQL injections).

The validationcode consists of 16 characters - (lower caps) letters and numbers. For example "d7c2xqz5tw1bj00v" or "4m3sh0bqkr1285gt"

In order to do this, I'm using:

$code = $_GET['code'];
if (!preg_match("/^[a-z0-9]{16}$/",$code)) die ("Invalid validationcode");

It seems to be working for validationcodes consisting of BOTH letters and numbers, however, I believe that the function generating the code (http://www.laughing-buddha.net/jon/php/password/) will sooner or later generate a code with only letters (as it contains 20 of them, each of which it will only use once in a code). Therefore, I also want the regular expression to accept a validation code consisting of only lower caps letters.

Your help is much appreciated. Best regards,

escanive
Last edited by escanive on Mon Sep 22, 2008 8:18 am, edited 1 time in total.
User avatar
Stryks
Forum Regular
Posts: 746
Joined: Wed Jan 14, 2004 5:06 pm

Re: need help with a regular expression

Post by Stryks »

Thar regex already accepts the following:

1a1a1a1a1a1a1a1a
1111111111111111
aaaaaaaaaaaaaaaa

(where 1 is any number, and a is any lowercase letter).

I can see any reason you would have any problems.
escanive
Forum Newbie
Posts: 2
Joined: Mon Sep 22, 2008 2:32 am

Re: need help with a regular expression

Post by escanive »

Stryks wrote:Thar regex already accepts the following:

1a1a1a1a1a1a1a1a
1111111111111111
aaaaaaaaaaaaaaaa

(where 1 is any number, and a is any lowercase letter).

I can see any reason you would have any problems.
My bad ^^; - must have done something wrong while testing. Thanks.
Post Reply