Checking if a string is made up of just emojis

Hi! I want to make a function that can take in a string and return a boolean if it is just made up of just emojis.

For example:

print(CheckForJustEmojis("๐Ÿ‘๐Ÿ˜ƒ๐ŸŽ"))
--result: true

print(CheckForJustEmojis("๐Ÿ‘hello"))
--result: false

I have no idea how to tackle this, Iโ€™ve tried searching Google and DevForum and couldnโ€™t find an answer to my problem. If anyone has any suggestions, that would be great! Thank you!

1 Like

I just found this in stack overflow and tested it in Studio, and it does detect if an emoji is in a string.

function starts_with_emoji(s)
	if not s:match("[%w]+") and  s:find"^\xF0\x9F[\x8C-\x9B]" or s:find"^\xE2[\x98-\x9F]" then
		return true
	else
		return false
	end
end

The script works for detecting emojis, but not just emojis unfortunately

The result was true with โ€œ:+1:โ€ but also true with โ€œ:+1: helloโ€, but it did return false to just โ€œhelloโ€

I fixed the code now. When there are only emojis, it will return true, but when there is an emoji first, then text together, it will return false, and if it is text alone, it will also return false.

it did not format right in this post i edited it in the last one.

2 Likes

It works perfectly! Thank you for your help!

1 Like

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