Created
July 17, 2016 01:47
-
-
Save blurymind/3dd8dbe96eca499e8e538e36d27d478a to your computer and use it in GitHub Desktop.
godot function that restricts a string to only use numbers - for numeric value input
This file contains hidden or 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
func _on_H_text_changed(): | |
hInput.set_text(returnNumbersOnly(hInput.get_text())) | |
hInput.cursor_set_column(hInput.get_text().length(),true) | |
## This function restricts the input to be only numeric### | |
func returnNumbersOnly(enteredText): | |
var word = '' | |
for letter in enteredText: | |
var resultingText = RegEx.new() | |
resultingText.compile('[0-9]',9) #search pattern | |
if resultingText.find(letter,0,-1) != -1 : word = word+letter | |
print('result is: ', word) | |
return word |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment