Mainly I am using regex, and what my code does essentially, is sends a client return code if it does not contain the characters in regex. My problem is, I do not know how to allow spaces.
Currently this is my code, I would like to have allow a space, a-z, A-Z and 0-9.
if (username.length() < 1 || username.length() >= 13
|| !username.matches("[a-zA-Z_0-9]"))
{
session.getLoginPackets().sendClientPacket(3);
return;
}
The regex you’re looking for is
[a-zA-Z_0-9][a-zA-Z_0-9 ]*assuming you don’t want a name to start with spaces.