Skip to content

Instantly share code, notes, and snippets.

@WuXianglong
Created November 18, 2015 02:49
Show Gist options
  • Save WuXianglong/771e60f796ebfa3d8bb3 to your computer and use it in GitHub Desktop.
Save WuXianglong/771e60f796ebfa3d8bb3 to your computer and use it in GitHub Desktop.
Regex to validate Android Package Name
var pattern = /^[a-z][a-z0-9_]*(\.[a-z0-9_]+)+[0-9a-z_]$/i;
[
"me.unfollowers.droid",
"me_.unfollowers.droid",
"me._unfollowers.droid",
"me.unfo11llowers.droid",
"me11.unfollowers.droid",
"m11e.unfollowers.droid",
"1me.unfollowers.droid",
"me.unfollowers23.droid",
"me.unfollowers.droid23d",
"me.unfollowers_.droid",
"me.unfollowers._droid",
"me.unfollowers_._droid",
"me.unfollowers.droid_",
"me.unfollowers.droid32",
"me.unfollowers.droid/",
"me:.unfollowers.droid",
":me.unfollowers.droid",
"me.unfollowers.dro;id",
"me.unfollowe^rs.droid",
"me.unfollowers.droid.",
"me.unfollowers..droid",
"me.unfollowers.droid._",
"me.unfollowers.11212",
"me.1.unfollowers.11212",
"me..unfollowers.11212",
"abc",
"abc.",
".abc"
].forEach(function(pkg) {
console.log('[' + (pattern.test(pkg) ? '✔' : '✘') + ']\t' + pkg);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment