Page 1 of 1

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

Posted: Mon Apr 06, 2009 11:39 am
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

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

Posted: Mon Apr 06, 2009 1:30 pm
by requinix
Regular expression.

Code: Select all

if (preg_match('/[^\w-]/', $string)) {
    // invalid
} else {
    // valid
}

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

Posted: Tue Apr 07, 2009 4:57 am
by markthien
thanks a lot man .... it works a like charm ! I love you !