检测base64编码 [英] Detect base64 encoding
本文介绍了检测base64编码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有谁知道一个jQuery插件,可以检查文字的base64恩偶然$ C $的CD?我希望能够脱code的base64字符串,但前提是字符串连接$ C $光盘开始。我看到几个剧本在那里,可以连接code和德code,但我真的一个可以检查字符串连接codeD。
Does anyone know of a jQuery plugin that can check if text is base64 encoded by chance? I want to be able to decode base64 strings but only if the string is encoded to begin with. I see several scripts out there that can encode and decode but I really one that can check if the string is encoded.
有没有这样的事情存在?
Does such a thing exist?
推荐答案
必须将它真正做到了jQuery插件?只需使用一个简单的JavaScript正则表达式匹配:
Must it really be a jQuery plugin? Just use a simple JavaScript regex match:
var base64Matcher = new RegExp("^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=|[A-Za-z0-9+/]{4})$");
// ...
if (base64Matcher.test(someString)) {
// It's likely base64 encoded.
} else {
// It's definitely not base64 encoded.
}
的正则表达式是由这个问题采取:正则表达式解析或验证的Base64数据。
这篇关于检测base64编码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文