...

View Full Version : Regular Expression help



ACJavascript
12-07-2003, 09:50 PM
Hello all,,

Okay I have a form with a username field. I dont want any funny characters in the username,, SO I have this REG Expression but its not working right..

if($Uname != "[-a-zA-Z0-9._"){


Pretty much this is suppost to say if theres anything other then a-ZA-Z or 0-9 Dont let them continue...

but its not working.

Any help is most apprecaited

ReadMe.txt
12-07-2003, 09:56 PM
you're not using a regular expression function, thats why

have a look at http://www.php.net/preg-match

ACJavascript
12-07-2003, 11:05 PM
You were right!

THanks alot ReadMe.txt!

ACJavascript
12-08-2003, 06:32 PM
Hey Readme,,

Okay this is working Half staff hehe..

heres the code now:

if(preg_match("/([a-zA-Z0-9])/",$Uname)){
}else{
//BAD STUFF IN USERNAME
}


okay,, this works if say the user puts in: !@#!@

Now if they do this: AC!#@#$ it doesn't pick it up.


So how can I get it to pick up the bad characters Period,, wether or not theres Normal characters in front of it.

Any help is most apprecaited.

bcarl314
12-08-2003, 06:58 PM
Try something like


preg_match("/^[a-zA-Z0-9]/g",$Uname);

raf
12-08-2003, 07:56 PM
I usualy have something like this to test usernames and pwd's


if ((strlen($user) < 5)) {
$err = (' Usernames must be at least 5 characters long.');
}
if (ereg('[^A-Za-z0-9]', $user)) {
$err = (' You can use only letters and numbers.');
if (ereg("['\"*_%.()]+", $user)) {
$err = ('<strong>SQL-injection attack?</strong>');
}
}

ACJavascript
12-08-2003, 09:12 PM
HEY RAF

that works perfectly thanks!

raf
12-08-2003, 09:55 PM
Glad you got it working.

I've set a few bug straigh from the code (i'de been cutting out my errorprocessing carelessly ... )



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum