Created
May 5, 2020 05:32
-
-
Save t-karcher/d656aa567eef117e2750bd1b6b9f5505 to your computer and use it in GitHub Desktop.
Filters out characters from input in LineEdit using a RegExp pattern of allowed characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extends LineEdit | |
var allowed_characters = "[A-Za-z]" | |
func _on_LineEdit_text_changed(new_text): | |
var old_caret_position = self.caret_position | |
var word = '' | |
var regex = RegEx.new() | |
regex.compile(allowed_characters) | |
for valid_character in regex.search_all(new_text): | |
word += valid_character.get_string() | |
self.set_text(word) | |
caret_position = old_caret_position |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Source: https://www.reddit.com/r/godot/comments/gdck9a/how_to_control_lineedit_inputs/