Godot_bridge/addon/common/validate_name.py
2023-03-29 12:43:53 +02:00

11 lines
No EOL
522 B
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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