...

View Full Version : Allow all preg-match



Haidar
06-01-2011, 10:23 PM
Hello people :D!

I was wondering if someone could help me, letting this code to allow all preg match. I think i have writed the preg-match wrong, i will allow all this symbols in my loginscript: - . : # & @ _ $

And this is the code:

else if (!preg_match('#^([0-9a-z@:.\-_;,!])*$#i', $subuser)) {

Chris Hick
06-02-2011, 12:12 AM
I recomend using varibles in this situation, my friend. Put all the things you want allowed in a variable and then put the variable into the preg_match function.

In this case:


$pattern = '/- . : # & @ _ $/';
$subuser = ' ';
else if (!preg_match($pattern, $subuser)) {
/// code

}



As I always say, I could be wrong.. Feel free to correct me anyone.

Haidar
06-02-2011, 02:50 AM
I recomend using varibles in this situation, my friend. Put all the things you want allowed in a variable and then put the variable into the preg_match function.

In this case:


$pattern = '/- . : # & @ _ $/';
$subuser = ' ';
else if (!preg_match($pattern, $subuser)) {
/// code

}



As I always say, I could be wrong.. Feel free to correct me anyone.

Alright :o seems very good! But please could you write it for me instead in the same way as my line? Because i'm not so god in php and im using a bit for diffucult script, when i change to your lines i got error message. So maybe the best way is just modify the line i put? i would be very happy if you could help me!

Haidar
06-02-2011, 07:26 PM
I still need help :/

Chris Hick
06-02-2011, 11:38 PM
What exactly are you trying to do? Are you trying to make sure the username is within a certain limit and will only allow those character mentioned above?

Haidar
06-02-2011, 11:55 PM
What exactly are you trying to do? Are you trying to make sure the username is within a certain limit and will only allow those character mentioned above?

Yupp exactly! But the code is kind of wired, so i have to write them in the same line.

Chris Hick
06-03-2011, 12:06 AM
I have no clue why I didn't tell you this until now, it completely slipped my mind. You are better off using preg_match(); to search for things that you do not want in the username or something specific in the username that must be included. The preg_match function looks for the first match of what you tell it to look for then pops out 0 being false and 1 being true. So, you would be better off looking for what you don't want it to include rather than something you want it to allow.

Ahlahn
06-03-2011, 07:03 PM
I don't think your regex is correct since it won't match any letters or numbers. I may be wrong. This should work:

/^[- . : # & @ _ $a-zA-Z0-9]{1,}$/

It matches 1 or more of all the characters within the class, including letters and numbers.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum