Godot_bridge/addon/common/validate_name.py

11 lines
522 B
Python
Raw Permalink Normal View History

2023-03-29 10:43:53 +00:00
import re
def validate_name(name):
"""Check if the name is properly formatted
Must be in kebab-case, with possible underscore for prefixes/sufixes
and only alphanumerical
A-z0-9 doesnt seem to work in regexp, so had to write them full extent
"""
allowed = re.match(r'^([ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789]+)_?([ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-]+)_?([ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789]+)$', name)
return allowed is not None