• If string dosen't only contain letters
    4 replies, posted
I wanna set a players name. But he/she is not allowed to have symbols or numbers. if string.contains symbols and numbers then return else ply:setRPName(text) end
[lua]string.match( ply:Nick(), "[A-Za-z0-9]+" ) == ply:Nick()[/lua] Returns true if the player's name is valid
[QUOTE=JasonMan34;51211142][lua]string.match( ply:Nick(), "[A-Za-z0-9]+" ) == ply:Nick()[/lua] Returns true if the player's name is valid[/QUOTE] This is kinda confusing way to do it. I think this is better: [code] if ply:Nick():find("[^a-zA-Z]") then … end [/code]
[QUOTE=mijyuoon;51211502]This is kinda confusing way to do it. I think this is better: [code] if ply:Nick():find("[^a-zA-Z]") then … end [/code][/QUOTE] It may also be worth adding in \s and - to allow for names that have spaces or double-barrelled/ hyphenated names. Otherwise you're stuck to single word names. Which is somewhat boring.
[QUOTE=hexpunK;51211555]It may also be worth adding in \s and - to allow for names that have spaces or double-barrelled/ hyphenated names. Otherwise you're stuck to single word names. Which is somewhat boring.[/QUOTE] I fully agree that it would be better, but I just did what the guy asked. Maybe he doesn't want spaces/hyphens for some weird reason. Also it's %s in Lua patterns instead of \s like in regexp.
Sorry, you need to Log In to post a reply to this thread.