最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Does Javascript string.toLowerCase() follow Unicode standards in case-conversions? - Stack Overflow

programmeradmin0浏览0评论

I'm creating a browser-based form verification script that checks if the input doesn't have any uppercase characters according to Unicode Standards. My definition of an uppercase character is a character that has a lowercase mapping. If a certain character in the input string doesn't have a lowercase or uppercase mapping (like chinese characters) then it's alright (it should pass my validation).

I'm using UTF-8 encoding.

I'm planning to create a function that looks like this:

function hasUpper(str){
  if(str != str.toLowerCase()){
    return true
  }
  else {
    return false
  }
}

Will this work for my needs?

Thanks!

I'm creating a browser-based form verification script that checks if the input doesn't have any uppercase characters according to Unicode Standards. My definition of an uppercase character is a character that has a lowercase mapping. If a certain character in the input string doesn't have a lowercase or uppercase mapping (like chinese characters) then it's alright (it should pass my validation).

I'm using UTF-8 encoding.

I'm planning to create a function that looks like this:

function hasUpper(str){
  if(str != str.toLowerCase()){
    return true
  }
  else {
    return false
  }
}

Will this work for my needs?

Thanks!

Share Improve this question edited May 3, 2019 at 5:48 Albert asked Aug 28, 2010 at 13:02 AlbertAlbert 3,6513 gold badges29 silver badges54 bronze badges 1
  • 3 Note that you can simplify that function to return str != str.toLowerCase(). – Eli Grey Commented Aug 28, 2010 at 16:31
Add a comment  | 

2 Answers 2

Reset to default 11

Yes, that will work. Incidentally, the Boolean keywords are true and false, lower case. :)

The question answered here seems to indicate that toLower and toUpper are Unicode-aware:Stack OverFlow

And this one goes into it in more detail (indicating that some mappings conflict with the real world):more Stack Overflow

Hope this helps!

发布评论

评论列表(0)

  1. 暂无评论