'LinKin Posted June 15, 2014 Share Posted June 15, 2014 Hello, I want to make a validation so that if a character that is NOT accepted by MTA as a possible player's nick part it outputs an error. So like this: if theNick:find("%W") then In that case, it will detect if there are non-alphanumerical characters present. But how could I make an exeption so that it accepts some non-alphanumerical characters that are allowed by MTA? For example a player can set his nick to |SW|'~(L)inKin. and MTA will accept it as the player's nick, but it does contain non-alphanumerical characters. Accepted symbols are: \|@#~!"$%&/()[]=?+*-.' However player's nick cannot contain these symbols: º ñ ç · and some others So which pattern for string.find should I use in this case? Thanks Link to comment
Gtagasje Posted June 16, 2014 Share Posted June 16, 2014 I'm not sure if this would work (don't have time to test it) but you could atleast try it. local charTable = {["\\"] = true, ["|"] = true, ["/"] = true, ["@"] = true, ["#"] = true, ["~"] = true, ["!"] = true, ["\""] = true, ["$"] = true, ["%"] = true, ["&"] = true, ["("] = true, [")"] = true, ["["] = true, ["]"] = true, ["="] = true, ["?"] = true, ["+"] = true, ["-"] = true, ["*"] = true, ["."] = true, ["'"] = true} if newNick:find("%W") and not charTable[newNick:find("%W")] then Basically you add all the allowed characters in a table, and then check that if a non-alphanumerical character is found and it's not in the table then you cancel it. 1 Link to comment
cheez3d Posted June 16, 2014 Share Posted June 16, 2014 if not ("Cheez"):find("[^%w%d\\|@#~!\"%$%%%^&/%(%)%[%]=%?%+%*%-%.']") then outputChatBox("Valid nickname!"); end; 1 Link to comment
'LinKin Posted June 21, 2014 Author Share Posted June 21, 2014 Tested these two examples but any of them is giving a 100% result. So I was thinking to make a custom table in which I'd put the symbols that are accepted, but how can I check if a character from a string matches with any of the symbols previously defined? Basically, how can I loop character by character into an string? Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now