Test if string contains only letters (a-z + é ü ö ê å ø etc..)

后端 未结 12 1305
不思量自难忘°
不思量自难忘° 2020-12-04 18:12

I want to match a string to make sure it contains only letters.

I\'ve got this and it works just fine:

var onlyLetters = /^[a-zA-Z]*$/.test(myString)         


        
12条回答
  •  醉梦人生
    2020-12-04 18:39

    I don't know anything about Javascript, but if it has proper unicode support, convert your string to a decomposed form, then remove the diacritics from it ([\u0300-\u036f\u1dc0-\u1dff]). Then your letters will only be ASCII ones.

提交回复
热议问题