I know that it may be too late to answer, but this is what I came to. In this case, I use {match} in jQuery. This applies to images or texts. Hope this helps
var sSampleBase64Text = 'data:text/plain;base64,MSkgTG9naW4gRGV0YWlscwogPj4gdGNfYWRtaW5fYXllZQogPj4gdHdpbmtsZXMyMnRo';
var mCheckMatchResult = sSampleBase64Text.match(/^(?:[data]{4}:(text|image|application)\/[a-z]*)/);
var sAlertMessage = 'Valid base 64 encode string';
if (mCheckMatchResult === null || mCheckMatchResult.length <= 0) {
sAlertMessage = 'Not a valid base 64 encode string';
}
$('.result').append('<p>' + sAlertMessage + '</p>');
Try looking here:
https://jsfiddle.net/lajatomary/a8tugwe3/4/
source
share