Don't click here unless you want to be banned.

LSL Wiki : ExampleIsValidKey

HomePage :: PageIndex :: RecentChanges :: RecentlyCommented :: UserSettings :: You are ia360925.us.archive.org
Function that will check wether a string is correctly formatted to be converted (casted) to a key.

// Check if a string is convertable to a key.
// Produced by Logic Scripted Products and Script Services
// Flennan Roffo

integer IsValidKeyFormat(string str)
{
    string keychars = "0123456789abcdef";

    if (llStringLength(str) != 36)
        return FALSE;
        
    if (   (llGetSubString( str, 8, 8 )    != "-" ||
             llGetSubString( str, 13, 13 ) != "-" ||
            llGetSubString( str, 18, 18 ) != "-" ||
            llGetSubString( str, 23, 23 ) != "-" ) )
        return FALSE;

    integer i;
    
    for (i = 0; i < 8; ++i)
    {
        if (llSubStringIndex(keychars, llGetSubString(str,i,i)) == -1)
            return FALSE;
    }

    for (i = 9; i < 13; ++i)
    {
        if (llSubStringIndex(keychars, llGetSubString(str,i,i)) == -1)
            return FALSE;
    }

    for (i = 14; i < 18; ++i)
    {
        if (llSubStringIndex(keychars, llGetSubString(str,i,i)) == -1)
            return FALSE;
    }

    for (i = 19; i < 23; ++i)
    {
        if (llSubStringIndex(keychars, llGetSubString(str,i,i)) == -1)
            return FALSE;
    }

    for (i = 24; i < 36; ++i)
    {
        if (llSubStringIndex(keychars, llGetSubString(str,i,i)) == -1)
            return FALSE;
    }

    return TRUE;
}
There is no comment on this page. [Display comments/form]