7 Replies
im trying to write a statement to check if a string contains only alphanumeric characters
an example would be
Fast Food Emporium
Servator
REPL Result: Success
Result: bool
Compile: 247.642ms | Execution: 17.679ms | React with ❌ to remove this embed.
Servator
REPL Result: Success
Result: bool
Compile: 291.154ms | Execution: 17.143ms | React with ❌ to remove this embed.
Looks like neither of them
if ((nameCheck.Any(char.IsLetterOrDigit) == false) || (nameCheck.Length > 5))
thats what ive got
but spaces
are flagging it
as false
for valid names
You could .Trim() i guess
So your validation isn't just alphanumeric, its alphanumeric and spaces.
so write your own helper method for that. Something like
should work, but you might want to restrict it to just spaces instead of any whitespace.