简体   繁体   中英

Checking if name of a person is valid or not

I am working on a project in which I have to figure out if the name of a person is valid or not. One case of invalidity is a single character name.

In English, it is straight forward to figure out by checking the length.

if len(name) < 2:
    return 0

I am not sure if checking length will work out for other languages to, like 玺. I am not sure if this is one character or something else.

Can someone help me to solve this issue?

Dataset info: countries: 125 total names: 11 Million

Maybe use a dictionary:

language_dict = {
'english':2,
'chinese':1
}

if len(name) < language_dict['english']:
    return 0

While I can't vouch for all other languages, checking a python script with the character you provided confirms that according to Python it is still a single character.

print(len("玺"))

if len("玺") < 2:
    print("Single char name")

Another potential solution would be to check ord(char) (29626 for the given char) to check if it is outside the standard latin alphabet and perform additional conditional checks.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM