Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
161
rated 0 times [  168] [ 7]  / answers: 1 / hits: 104756  / 13 Years ago, sat, october 22, 2011, 12:00:00

I'm using the window.atob('string') function to decode a string from base64 to a string. Now I wonder, is there any way to check that 'string' is actually valid base64? I would like to be notified if the string is not base64 so I can perform a different action.


More From » base64

 Answers
15

If valid means only has base64 chars in it then check against /[A-Za-z0-9+/=]/.



If valid means a legal base64-encoded string then you should check for the = at the end.



If valid means it's something reasonable after decoding then it requires domain knowledge.


[#89489] Thursday, October 20, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
draven

Total Points: 641
Total Questions: 101
Total Answers: 110

Location: Nicaragua
Member since Mon, Sep 26, 2022
2 Years ago
draven questions
Tue, Apr 12, 22, 00:00, 2 Years ago
Thu, Feb 17, 22, 00:00, 2 Years ago
Tue, Nov 30, 21, 00:00, 3 Years ago
Tue, Oct 19, 21, 00:00, 3 Years ago
;