$username validation
Moderator: General Moderators
$username validation
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?
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?
- prometheuzz
- Forum Regular
- Posts: 779
- Joined: Fri Apr 04, 2008 5:51 am
Re: $username validation
No, it only applies to the 8 bit ascii character set. You could try a regex like this:jsha wrote:... Does \w apply to all international characters?
Code: Select all
'/-_\d\p{L}/'u
// 'u' at the end is the unicode flag
// '\p{L}' is any unicode letterRe: $username validation
Does \d represent any digit in Unicode?prometheuzz wrote:No, it only applies to the 8 bit ascii character set. You could try a regex like this:jsha wrote:... Does \w apply to all international characters?Code: Select all
'/-_\d\p{L}/'u // 'u' at the end is the unicode flag // '\p{L}' is any unicode letter
- prometheuzz
- Forum Regular
- Posts: 779
- Joined: Fri Apr 04, 2008 5:51 am
Re: $username validation
No, that's also only the 0-9 from the ascii set. If you want unicode numbers, use \p{N}jsha wrote:...
Does \d represent any digit in Unicode?
- prometheuzz
- Forum Regular
- Posts: 779
- Joined: Fri Apr 04, 2008 5:51 am
Re: $username validation
Oh, and the regex I posted earlier, should have been this, of course:
Code: Select all
'/^[-_\d\p{L}]+$/'uRe: $username validation
So this should do the trick?prometheuzz wrote:Oh, and the regex I posted earlier, should have been this, of course:
Code: Select all
'/^[-_\d\p{L}]+$/'u
Code: Select all
'/^[-_\d\p{N}]+$/'u- prometheuzz
- Forum Regular
- Posts: 779
- Joined: Fri Apr 04, 2008 5:51 am
Re: $username validation
No, this:
Code: Select all
'/^[-_\p{N}\p{L}]+$/'u // unicode letters, unicode numbers, underscores and hyphensRe: $username validation
prometheuzz wrote:No, this:Code: Select all
'/^[-_\p{N}\p{L}]+$/'u // unicode letters, unicode numbers, underscores and hyphens
Thanks Mate!
- prometheuzz
- Forum Regular
- Posts: 779
- Joined: Fri Apr 04, 2008 5:51 am
Re: $username validation
You're welcome!jsha wrote:...
Thanks Mate!