I know this might be late to answer but this is what I came up so far. In this case, I use the {match} in jQuery. This is applicable for 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 to look this up here:
https://jsfiddle.net/lajatomary/a8tugwe3/4/