What is a good Regex for a valid minecraft username?

Any help topics that don't fit in the current categories can go here.
Post Reply
User avatar
offluffy
Posts: 65
Joined: Tue Mar 20, 2012 7:04 am

What is a good Regex for a valid minecraft username?

Post 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.
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

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

Post 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 ;)
Image
User avatar
offluffy
Posts: 65
Joined: Tue Mar 20, 2012 7:04 am

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

Post 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
Post Reply