Skip to content

Instantly share code, notes, and snippets.

@blurymind
Created July 17, 2016 01:47
Show Gist options
  • Save blurymind/3dd8dbe96eca499e8e538e36d27d478a to your computer and use it in GitHub Desktop.
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
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