Skip to content

Instantly share code, notes, and snippets.

@RyanNutt
Created June 16, 2017 14:53
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save RyanNutt/fe1836843a4257a4a362b2f551213835 to your computer and use it in GitHub Desktop.
Save RyanNutt/fe1836843a4257a4a362b2f551213835 to your computer and use it in GitHub Desktop.
Check if a String is base64 encoded using JavaScript - from https://stackoverflow.com/a/34068497/1561431
function isBase64(str) {
try {
return btoa(atob(str)) == str;
} catch (err) {
return false;
}
}
@naothomachida
Copy link

Thanks!

@roccomuso
Copy link

This doesn't work on Node.js env.

@jameskbecker
Copy link

This doesn't work on Node.js env.

you probably didn't install atob and btoa npm packages

@lovelmh13
Copy link

if test XXXL or 75ml or sth, is doesn't work

@derrick-null
Copy link

Any string of 4 characters, consisting of letters and numbers, can pass the check.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment