Page 1 of 1

What is a good Regex for a valid minecraft username?

Posted: Thu Mar 29, 2012 9:37 pm
by offluffy
So I have this piece of code:
Pattern pattern = Pattern.compile(""); 
I just need to know a way to check to see if a given string matches what is considered a "valid" username for legit minecraft clients. So far I know that it can contain up to 16 characters, only having alpha-numeric characters and underscores. Sorry if this is a dumb question, but I've never quite been able to work out Regex patterns very well. Currently also trying to find out if the naming standard has changed any with the introduction of non-english characters and what-not @.@

Well, I tried figuring out what the new standards are to date, but apparently regex and java plugins have nothing to with programming and was utterly shunned on stackoverflow, so I got nothing on there. Happen to know if they're still the same?

I'm kinda guessing it'll be something like this:
Pattern pattern = Pattern.compile("[A-Za-z0-9_]{2,16}"); 
But then again, I suck at regex.

Re: What is a good Regex for a valid minecraft username?

Posted: Sat Mar 31, 2012 11:33 pm
by jacek
That looks basically right to me, I would have to try it to see.

The expression I used in php was
#[a-z0-9_]{2,16}#i
which is pretty similar. the i at the end makes is vase insensitive (not something java can do).

If the syntax is correct then the one you have will match only valid account names, just try and compile it ;)

Re: What is a good Regex for a valid minecraft username?

Posted: Sat Mar 31, 2012 11:37 pm
by offluffy
Oh yes. I tried it and it works alrighty to my knowledge XD And the case "insensitive" part I guess has to come from the 'A-Za-z' part. But thanks XD