how to block text with non English letters

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

how can i do this with this code

var normal_char = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","1","2","3","4","5","6","7","8","9","0"]

func _on_LineEdit_text_entered(new_text):
	if new_text != "":if !new_text in FS.level_names:
		level_name = new_text
		level_path = "res://saves/scene_saves/"+str(level_name)
		$Label.text = level_name
		$Label.visible = true
		can_play = true
		FS.level_names += [level_name]

when i use

if !new_text.find(normal_char) <=0:

it dont work


ramazan | 2022-02-05 14:00

it prints:


[a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0]

Ktotoetoia | 2022-02-05 14:23


ramazan | 2022-02-05 14:39

but when i use


it prints correctly

Ktotoetoia | 2022-02-05 17:04

:bust_in_silhouette: Reply From: Wakatta

Try a for loop

for _char in new_text:
    if _char not in normal_char:
        return #exit the _on_LineEdit_text_entered func

where the return is in the code you can replace with a function to notify of invalid entry for example

$LineEdit.set_placeholder("Please enter valid text")

Strings also have a is_valid_identifier func

if new_text.is_valid_identifier:
    if !new_text.has("_"):

Thank you!!!

Ktotoetoia | 2022-02-05 18:28