Allow special characters &,-,_ for ship name and callsign
This commit is contained in:
parent
7fea4d27b7
commit
62bd6304c4
@ -1,20 +1,19 @@
|
|||||||
import typing
|
import typing
|
||||||
from string import ascii_letters, digits
|
import re
|
||||||
|
|
||||||
|
|
||||||
|
_VALID = re.compile(r'^[\w &-]+$') # \w == Unicode letters+digits+underscore
|
||||||
|
|
||||||
def check_if_string_has_special_characters(text:typing.Optional[str]):
|
def check_if_string_has_special_characters(text:typing.Optional[str]):
|
||||||
"""
|
"""
|
||||||
check, whether there are any characters within the provided string, which are not found in the ascii letters or digits
|
check, whether there are any characters within the provided string, which are not found in the ascii letters or digits
|
||||||
ascii_letters: abcd (...) and ABCD (...)
|
|
||||||
digits: 0123 (...)
|
|
||||||
|
|
||||||
|
Formerly, this solution was used but was found to be too restrictive:
|
||||||
Source: https://stackoverflow.com/questions/57062794/is-there-a-way-to-check-if-a-string-contains-special-characters
|
Source: https://stackoverflow.com/questions/57062794/is-there-a-way-to-check-if-a-string-contains-special-characters
|
||||||
User: https://stackoverflow.com/users/10035985/andrej-kesely
|
User: https://stackoverflow.com/users/10035985/andrej-kesely
|
||||||
returns bool
|
returns bool
|
||||||
"""
|
"""
|
||||||
if text is None:
|
return not _VALID.fullmatch(text) if text else False
|
||||||
return False
|
|
||||||
return bool(set(text).difference(ascii_letters + digits + ' '))
|
|
||||||
|
|
||||||
|
|
||||||
def check_if_int_is_valid_flag(value, enum_object):
|
def check_if_int_is_valid_flag(value, enum_object):
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user