Jump to content

Unicode password


Illasera

Recommended Posts

am looking for a function or a way/method to report an error once a unicode character(NONE-ASCII) found in a string.I have a registration form and i don`t want users to be able to enter unicode passwords(none-ascii), how do i report an error was unicode character within a string was found?I couldn`t find the right filter function for it...Thanks in advance.

Link to comment
Share on other sites

What do you consider a unicode character? The Unicode character set includes every single character that can be typed on a computer. That also includes A, B, C...If you only want letters, numbers and underscores you can use a regular expression, something like this: [a-zA-Z0-9_]+

Link to comment
Share on other sites

What do you consider a unicode character? The Unicode character set includes every single character that can be typed on a computer. That also includes A, B, C...If you only want letters, numbers and underscores you can use a regular expression, something like this: [a-zA-Z0-9_]+
Not ascii a-z/A-Z, 0-9, yep,But what do you mean "use a regular expression"?should i write a "for" loop that iterate through the strings and check for bad characters?I was hoping to find a function that does it for me...
Link to comment
Share on other sites

The best thing is to use a regular expression that allows ONLY permitted characters. So

function isValid($str) {   $re = '/[^a-zA-Z0-9]/'; // add permitted characters between the [braces]   return !preg_match($re, $str);}// small test$password = "mypassword";if (isValid($password) ) {   echo 'Valid';}$password = "mypésswürd";if (isValid($password) ) {   echo 'Valid';} else {   echo 'Not valid';}

I wrote this mostly from memory. Be sure to test it.

Link to comment
Share on other sites

Not ascii a-z/A-Z, 0-9, yep,But what do you mean "use a regular expression"?should i write a "for" loop that iterate through the strings and check for bad characters?I was hoping to find a function that does it for me...
That is precisely what a regular expression does. It's a pattern against which a string is tested. They're extremely useful but can be intimidating at first because of the syntax. :) php regex and you'll find a lot of documentation on the functions that use it.
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...