how to accept input with only alphabet, numeric, hypen and u

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
markthien
Forum Commoner
Posts: 33
Joined: Fri Feb 13, 2009 7:50 pm

how to accept input with only alphabet, numeric, hypen and u

Post by markthien »

Hi guys,

I need to check if user enter only alphabet, numeric, hypen and underscore like "mark_thien-01", "markthien" or "mark0" or "mark_1" is valid. Appreciate any help please.

Thanks & Regards,
Mark Thien
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: how to accept input with only alphabet, numeric, hypen and u

Post by requinix »

Regular expression.

Code: Select all

if (preg_match('/[^\w-]/', $string)) {
    // invalid
} else {
    // valid
}
markthien
Forum Commoner
Posts: 33
Joined: Fri Feb 13, 2009 7:50 pm

Re: how to accept input with only alphabet, numeric, hypen and u

Post by markthien »

thanks a lot man .... it works a like charm ! I love you !
Post Reply