This code checks for invalid whitespace but can still be invalid UTF8. Websockets as text must be utf8.
// Check for invalid whitespace characters
if (*ptr < 32 && *ptr > 0 && !(*ptr >= 8 && *ptr <= 13 && *ptr != 11)) {
length = stringlcpy(pDest, "Invalid String", maxLength+1);
length = length > maxLength ? maxLength : length;
return length;
}