Forum Moderators: coopster

Message Too Old, No Replies

Giving warnings for username / passwords

         

duckxtales

7:51 am on Dec 7, 2006 (gmt 0)

10+ Year Member



Hi,

I'm trying to implement a username and password on my site and i want to know the function that lets me scan a variable for unappropiate characters like these ':"!@#$%^&*()_+~

thx

mcibor

9:39 am on Dec 7, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You can check that with regex, but easier is checking if it's alphanumeric with
ctype_alnum [php.net]

or

regex
^[A-Za-z0-9]+$

preg_match('/^[a-z0-9]+$/iD', $text);

Regards
Michal

duckxtales

5:33 pm on Dec 7, 2006 (gmt 0)

10+ Year Member



thanks..

does anyone know how i can strip all tags and punctuations in a variable? i know one of them is stripslahses or something like that. what else do i need?

eelixduppy

8:11 pm on Dec 7, 2006 (gmt 0)



>> strip all tags
strip_tags [us2.php.net]

>> and punctuations


$pattern = "/[^\w\s]/";
echo [url=http://us2.php.net/manual/en/function.preg-replace.php]preg_replace[/url]($pattern,'',$string);

Good luck :)

justageek

8:37 pm on Dec 7, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Make sure you read the warnings on using strip_tags(). I have found that it does not always work as you think it should.

JAG

duckxtales

11:28 pm on Dec 7, 2006 (gmt 0)

10+ Year Member



thanks JAG..

Can someone explain this:

$pattern = "/[^\w\s]/";

I know its regular expressions, but its a bit confusing.

"/ - start of the pattern

[^ - negate the following

\w - anything digits?

\s - anything with letters?

] - closing bracket of the regular expression

/" - end of the pattern

Am I correct on the above? I had to spend some good amount of time learning it.

thx

eelixduppy

4:00 am on Dec 8, 2006 (gmt 0)



>>>\w - anything digits?

Actually, \w represents any "word" character, which is alphanumeric and the underscore.

>>>\s - anything with letters?

Space characters

Refer to Pattern Syntax [us3.php.net] or Regular Expressions Explained [webmasterworld.com] for more details.

Best of luck!