Jump to content

Unicode password


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.

Edited by Illasera
Link to post
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 post
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... Edited by Illasera
Link to post
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.

Edited by Deirdre's Dad
Link to post
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 post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...