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
		$LineEdit.queue_free()
		FS.level_names += [level_name]
		FS.save_data(level_name+".txt",FS.level_names)

when i use

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

it dont work

try
print(normal_char)
and
print(new_text)

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

print(new_text.find(normal_char))

ramazan | 2022-02-05 14:39

-1
but when i use

print(newtext.find("a"))

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.clear()
$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("_"):
        return

Thank you!!!

Ktotoetoia | 2022-02-05 18:28