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?
DID My Home Work Can You Please Check.
Moderator: General Moderators
- greyhoundcode
- Forum Regular
- Posts: 613
- Joined: Mon Feb 11, 2008 4:22 am
Re: DID My Home Work Can You Please Check.
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:
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_\-]+$/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_\-]+$