Atul gave a great answer.
As far as I can remember the format looks like:
data:<MIME>[;<charset>];base64,.......
Here we need to check first the valid MIME types for image:
image/gif, image/png, image/jpeg, image/bmp, image/webp
Usually the charset is charset=utf-8 but it might not be there as well.
This is not rigorous checking but your final regex should be along these lines:
/^data:image\/(?:gif|png|jpeg|bmp|webp)(?:;charset=utf-8)?;base64,(?:[A-Za-z0-9]|[+/])+={0,2}/g