PcoWSkbVqDnWTu_dm2ix
We use cookies on this site to enhance your user experience

Vowel Detector

Vowel Detector

Oct 01 2018, 2:22 AM PST

This code sample, when placed within a TextBox, will turn the text color red if the typed string contains no vowels (A, E, I, O or U).

local textBox = script.Parent

local function hasVowels(str)
	return str:lower():find("[aeiou]")
end

local function onTextChanged()
	local text = textBox.Text
	-- Check for vowels
	if hasVowels(text) then
		textBox.TextColor3 = Color3.new(0, 0, 0) -- Black
	else
		textBox.TextColor3 = Color3.new(1, 0, 0) -- Red
	end
end
textBox:GetPropertyChangedSignal("Text"):Connect(onTextChanged)