确定是否字符串中使用JavaScript是用base64 [英] Determine if string is in base64 using JavaScript

查看:138
本文介绍了确定是否字符串中使用JavaScript是用base64的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用了 window.atob('字符串')​​函数去code从BASE64为一个字符串的字符串。现在我不知道,有没有什么办法来检查'串'实际上是有效的base64?我想如果字符串不是BASE64得到通知,所以我可以执行不同的操作。

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.

推荐答案

如果有效的意思是只有在它的base64字符,然后核对 [A-ZA-Z0-9 + / = ]

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

如果有效指的是合法的base64恩codeD字符串,那么你应该在最后检查 =

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.

这篇关于确定是否字符串中使用JavaScript是用base64的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆