Search code examples
pythonunicodevalidationcharacter-properties

Validating a Unicode Name


In ASCII, validating a name isn't too difficult: just make sure all the characters are alphabetical.

But what about in Unicode (utf-8) ? How can I make sure there are no commas or underscores (outside of ASCII scope) in a given string?

(ideally in Python)


Solution

  • Just convert bytestring (your utf-8) to unicode objects and check if all characters are alphabetic:

    s.isalpha()
    

    This method is locale-dependent for bytestrings.