How to check if a string only consists of letters

I’ve made a UI where a player can input his first name but it may only consits of letter. So I want to check if it only consits of letters so the player could get an error if he fills other things in. With letters I mean letters A to Z.

This should return true if the string you provide is only containing letters. In any other case it will return false.

function isLetters(input)
	return string.match(input, "^[a-zA-Z]+$") ~= nil
end

If you would like for it to also permit spaces, you can include a %s like this:

function isLetters(input)
	return string.match(input, "^[a-zA-Z%s]+$") ~= nil
end
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.