|
|
|
|
Reply From: |
fpicoral |
With latin characters you mean ã, ñ, õ, é, etc, right?
And you want to block the limit of characters to 10 or you can’t type more than 10?
If you want to block up to 10 characters and the latin letters that you mentioned are the ones above, go to the node inspector and set the Max Length
to 10.
To check if the text contains a latin letter, what you could do were link the LineEdit
signal text_changed
to its script and use the find()
method to see if the text contains the letters that you want to check.
To be more pratical, I would suggest using a for
loop, like this:
extends LineEdit
var latin_characters = ["ã", "ñ", "ó"] #Add all the characters that you want to look for
func _on_LineEdit_text_changed(new_text):
for letter in latin_characters:
if new_text.find(letter) > 0: #If it's not present, return -1
print("Latin character %s found!"%letter)
If you want to make sure it’s ONLY latin characters, you could create another array with all the other characters and do the reverse logic, to make sure there are only the desired characters.
extends LineEdit
var latin_characters = ["ã", "ñ", "ó"] #Add all the characters that you want to look for
var normal_char = ["a", "b", "c"]
func _on_LineEdit_text_changed(new_text):
var only_latin = true
for normal in normal_char:
if new_text.find(normal) >= 0:
only_latin = false
if only_latin:
for letter in latin_characters:
if new_text.find(letter) >= 0: #If it's not present, return -1
print("Latin character %s found!"%letter)
else:
print("Only latin letters please!")
fpicoral | 2019-02-06 01:05
And to count the ammount of latin letters, the code would be this one, where amount
is the amount of latin characters:
extends LineEdit
var latin_characters = ["ã", "ñ", "ó"] #Add all the characters that you want to look for
var normal_char = ["a", "b", "c"]
var amount = 0
var text_array = []
func _on_LineEdit_text_changed(new_text):
var only_latin = true
count_latin_letters()
for normal in normal_char:
if new_text.find(normal) >= 0:
only_latin = false
if only_latin:
for letter in latin_characters:
if new_text.find(letter) >= 0: #If it's not present, return -1
print("Latin character %s found!"%letter)
else:
print("Only latin letters please!")
func count_latin_letters():
text_array = []
amount = 0
for i in text:
text_array.append(i)
for letter in text_array:
if letter in latin_characters:
amount += 1
fpicoral | 2019-02-06 01:12
Your code helped me a lot, thanks! <3
p.s. I meant just “normal_char” (no latin), just wrote wrong
WellStacked | 2019-02-06 01:27
Glad I could help!
If you need help with something else, please ask!
fpicoral | 2019-02-06 01:59