hi
for my unity game i’m creating a register menu, what i want is to check if the inputs are string type and not containing numeric values or special caracters
Regular Expressions seem to be what you are looking for; at least the way I interpret your question. The syntax might be a bit unintuitve, but that is something where internet can help. Here is a small example:
public bool IsValidName(string input)
{
return System.Text.RegularExpressions.Regex.IsMatch(input, "[^A-Za-z]");
}
The ‘pattern’ says the following:
- “[^A-Za-z**]**”: Any one character between the square-brackets.
- “[**^**A-Za-z]”: Make that any character, except all others between the brackets (its position is important).
- “[^A-Za-z]”: Character in the range of ‘A’ up to ‘Z’. The hyphen is an indication for this.
Now, if the inputted string contains a character that is not a letter from A to z (either upper- or lowercase), the inputted string is ‘illegal’. If you need some more characters, you should add them as you see fit, note though that there are a few special characters. Here is the relevant page.
2 Likes
Thanks Mr. Mud, i found the solution in
if (!name.All(char.IsLetter))
that works fine for me, your solution is very interesting
1 Like