Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

Copy link

@naothomachida naothomachida commented Aug 12, 2020

Thanks!

@roccomuso

This comment has been minimized.

Copy link

@roccomuso roccomuso commented Aug 31, 2020

This doesn't work on Node.js env.

@jameskbecker

This comment has been minimized.

Copy link

@jameskbecker jameskbecker commented Sep 5, 2020

This doesn't work on Node.js env.

you probably didn't install atob and btoa npm packages

@lovelmh13

This comment has been minimized.

Copy link

@lovelmh13 lovelmh13 commented Sep 26, 2020

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

@derrick-null

This comment has been minimized.

Copy link

@derrick-null derrick-null commented Oct 20, 2020

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