Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Cakee |
I would like for an @ symbol to be entered by the user in a textedit, however am unsure of how to code for a verification system on what is entered.
Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Cakee |
I would like for an @ symbol to be entered by the user in a textedit, however am unsure of how to code for a verification system on what is entered.
Reply From: | deaton64 |
Hi,
Are you looking to verify it’s an email address?
You can use regex as a simple test, based on this Stack Overflow page
Or if you want to check the @ symbol is in the text, you can use in
Both like this:
extends Node2D
var email1 = "me@here.com"
var email2 = "me.here.com"
var email3 = "me@here"
func _ready() -> void:
var regex = RegEx.new()
regex.compile("^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\\.[a-zA-Z0-9-.]+$")
print(regex.search(email1))
print(regex.search(email2))
print(regex.search(email3))
print("@" in email1)
print("@" in email2)
print("@" in email3)
So the output of the above would be:
[RegExMatch:1192]
[Object:null]
[Object:null]
True
False
True
Only 1 valid email address, but 2 contain an @ symbol.
Hopefully, that’s what you mean