Page 1 of 1

DID My Home Work Can You Please Check.

Posted: Fri Aug 29, 2008 7:32 pm
by jsha
Ok Im doing a registration form validation for the username. I only want a-z, A-Z, 0-9, dashs and underscores. Any advise or changes are welcome.

Here it goes.

elseif(!preg_match('/^[-\w]*$/', $username) ) $err=$lang['err_signup17'];

I also searched all over the web for making this work with international characters if I want the site to be in other languages could not find anything can any way help with that please. Does \w apply to all international characters?

Re: DID My Home Work Can You Please Check.

Posted: Sun Aug 31, 2008 2:20 am
by greyhoundcode
I didn't realise that \w represented all alphanumeric characters. Handy to know. Even so, for clarity when I'm debugging I would probably stick to something more plain vanilla:

Code: Select all

/^[a-zA-Z0-9_\-]+$/
As far as your internationalisation goes, an equivalent function to ereg_match() is mb_ereg_match() which, as the prefix mb_ suggests, has multi-byte support and thus will work with various international character sets.

As I'm sure you noticed it's a POSIX regex not a PCRE, so, and I haven't tested this, if you use mb_ereg_match() you ought to remove your delimiters:

Code: Select all

^[a-zA-Z0-9_\-]+$