1921 shaares
10 private links
10 private links
6 results
tagged
base64
I want to decode a Base64 encoded string, then store it in my database. If the input is not Base64 encoded, I need to throw an error.
How can I check if a string is Base64 encoded?
^@(?=(.{4})$)[A-Za-z0-9+/]={0,2}$
if (paddingRequired) {
regex = /^(?:[A-Za-z0-9+\/]{4})*(?:[A-Za-z0-9+\/]{2}==|[A-Za-z0-9+\/]{3}=)?$/;
}
else {
regex = /^(?:[A-Za-z0-9+\/]){2,}(={0,2})$/;
}