Jump to content

String analyse


Recommended Posts

Hello, I would like to check a string (in a name) to see if the name contains 2 capital letters like for exemple Charlie_Chapplin.

I've already done that (it's for a RP server):

  
addEventHandler("onPlayerJoin", root, 
    function() 
        local playerName = getPlayerName( source ) 
        if string.find(playerName, "#") or not string.find(playerName, "_") then 
            kickPlayer ( source, "Invalid Name" ) 
        end 
        spawn(source) 
    end 
) 
  

Thank's in advance :)

Link to comment
addEventHandler ( "onPlayerJoin", root, 
    function ( ) 
        local playerName = getPlayerName ( source ) 
        if string.find ( playerName, "#" ) or not string.find ( playerName, "_" ) then 
            kickPlayer ( source, "Invalid Name" ) 
        else 
            local playerNameSplitted = split ( playerName, "_" ) 
            if ( isStringFirstLetterUppercase ( playerNameSplitted [ 1 ] ) and isStringFirstLetterUppercase ( playerNameSplitted [ 2 ] ) ) then 
                spawn ( source ) 
            else 
                kickPlayer ( source, "Invalid Name" ) 
            end 
        end 
    end 
) 
  
function isStringFirstLetterUppercase ( str ) 
    local letter = str:sub ( 1, 1 ) 
  
    return ( letter:upper ( ) == letter ) 
end 

Try it.

Link to comment

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...