Filtering unwanted characters!

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
User avatar
Joe
Forum Regular
Posts: 939
Joined: Sun Feb 29, 2004 1:26 pm
Location: UK - Glasgow

Filtering unwanted characters!

Post by Joe »

Hey. I have a problem with my registration script where users are entering unwanted characters like |, %, !, ), and so on. I was wondering if there is any technique to stop characters and numbers being entered apart from A-Z a-z 1-0. I know in most langauges theres a particular method but is there any for PHP.

Regards


Joe 8)
User avatar
PrObLeM
Forum Contributor
Posts: 418
Joined: Sun Mar 07, 2004 2:30 pm
Location: Mesa, AZ
Contact:

Post by PrObLeM »

User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

Or see http://php.net/ctype_alnum
E.g if(!ctype_alnum($string)){ echo 'Invalid Characters'; } else { .... }

(I'll do anything to avoid regex ;))
User avatar
MarK (CZ)
Forum Contributor
Posts: 239
Joined: Tue Apr 13, 2004 12:51 am
Location: Prague (CZ) / Vienna (A)
Contact:

Post by MarK (CZ) »

Regular expressions...

e.g.

Code: Select all

if (ereg("^їa-zA-Z0-9]+$", $input)) echo "Ok!";
User avatar
Joe
Forum Regular
Posts: 939
Joined: Sun Feb 29, 2004 1:26 pm
Location: UK - Glasgow

Post by Joe »

Thanks a lot. Everythink is running well now. And yeah mark i have heard around that its best to avoid regular expressions so i used your technique. :)

Regards


Joe 8)
Post Reply