How to limit character Input on TextEdit?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By mr-ro95

Hi, is there a way to limit the number of characters that you can input in TextEdit or just a way to disable typing in it when a condition is met?

Is it possible to only accept numbers as an input. If not, is there a way to detect if the text has letters?

func _on_TextEdit_text_changed():
	if $TextEdit.get_text().length() >  5:
		#Disable Typing

Thanks :slight_smile:

:bust_in_silhouette: Reply From: TyTYctA

You can use property readonly of TextEdit.
“bool readonly - If true read-only mode is enabled. Existing text cannot be modified and new text cannot be added.”

then add BackSpace button in Input Map for delete addition letter and change Textedit again.
enter image description here

This works, but I have multiple TextEdit so If I press backspace all of the TextEdit.readonly will be affected. Thanks for this though, I might just go for this anyway.

Last question, does TextEdit doesn’t support mobile devices? I’ve exported my game on android and all of the TextEdit are not showing.

mr-ro95 | 2019-03-04 13:13

You can use if stament to choose what TextEdit will be editable.
enter image description here

TyTYctA | 2019-03-04 13:58

Sorry, what I mean is if all TextEdit are readonly, then you click backspace and everything will be back to false. Anyway, I think TextEdit doesn’t work on mobile devices, so I might not use it anymore :frowning:

Thanks for helping.

mr-ro95 | 2019-03-05 00:48

Thanks for that super-simple code TyTYctA!! That’s just what I needed… 2 years later :stuck_out_tongue:

grognard3 | 2021-07-21 03:18