checking postdata validity with... ereg?

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
robster
Forum Contributor
Posts: 360
Joined: Wed Jul 16, 2003 8:28 am
Location: Sunshine Coast, Australia

checking postdata validity with... ereg?

Post by robster »

Hi,

I have a username field in a registration page I am creating. I've done a check to see if the user fills it in, if they don't it spits and tells them to fill it in. Now I want to do a check to see if they have illigal characters including spaces in the username postdata. ie (!@#$%^&*() ":;',./., etc etc ;))

I've had a good search through these forums and google and had a look at ereg but didn't fully understand it.

Just wondering if somebody could point me in a good direction or send a psuedo snippit or similar?

Any help appreciated.

Rob
User avatar
Skara
Forum Regular
Posts: 703
Joined: Sat Mar 12, 2005 7:13 pm
Location: US

Post by Skara »

preg > ereg

if underscores count,

Code: Select all

if (preg_match('/\w+/',$string)) {
If they don't,

Code: Select all

if (preg_match('/[a-z]+/i',$string)) {
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Post by Ambush Commander »

Looks like you probably want a tutorial on regular expressions (google that).
Post Reply