string patterns

How can limit input text to A-Z and 0-9 only? no punctuations, no emoji etc.
maybe giving an array A,B,C,D,E,F…

ref: http://www.lua.org/pil/20.2.html [import]uid: 96683 topic_id: 20808 reply_id: 320808[/import]

try this:

local str = "5gklkFGFF4543^%$tuiuyOKOKOJOIh"  
print ("Before: ",str)  
  
str = string.gsub(str,"[^%u%d]","")  
print("After: ",str)  

this prints in the console:

Before: 5gklkFGFF4543^%$tuiuyOKOKOJOIh  
After: 5FGFF4543OKOKOJOI  

Explanation:

The pattern breakdown:
“[^%u%d]”
%d - represents all digits (0-9)
%u - represents all upper case chars (A-Z)
[] - defines a set.
^ - complements the set. In other words, the set is reversed to include all characters NOT in the brackets.

our “string.gsub” command replaces any character that conform to this set with an empty space (""), stripping the string from all non-upper case and digit chars. [import]uid: 33608 topic_id: 20808 reply_id: 81916[/import]

thanks. this is one way.

in another way:
how can I say to user: your name contains illegal chars or like that.
checking string if contains chars out of array? true/false [import]uid: 96683 topic_id: 20808 reply_id: 81956[/import]

[code]
local function validateName(str)
local result = true;
if string.find(str,"[^%u%d]") then
result = false;
end
return result;
end
local str1 = “GOODNAME”;
local str2 = “Bad Name !@$”;

if validateName(str1) then
print(str1…" is a valid name");
else
print(str1…" contains illegal chars ");
end

if validateName(str2) then
print(str2…" is a valid name");
else
print(str2…" contains illegal chars");
end

[/code] [import]uid: 33608 topic_id: 20808 reply_id: 81990[/import]

thanks for all.
Also I did like that.

string.find(nameEntered,"[^ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789]" [import]uid: 96683 topic_id: 20808 reply_id: 82024[/import]