Base64バリデーター
文字列を貼り付けて有効なBase64かをチェック。Base64文字セット、パディングの正確性、MIMEタイプを分析します。100%クライアントサイド。
100%クライアントサイド — データがデバイスから離れることはありません
Paste a Base64 string above to validate it
コード例
プロジェクトにすぐに使えるコードスニペットです。
JavaScript
// Validate Base64 with regex + decode attempt
function isValidBase64(str: string): boolean {
// Strip data URI prefix if present
const clean = str.includes(",") ? str.split(",")[1] : str;
// Quick character check
if (!/^[A-Za-z0-9+/]*={0,2}$/.test(clean)) return false;
// Length must be multiple of 4
if (clean.length % 4 !== 0) return false;
// Try decoding
try {
atob(clean);
return true;
} catch {
return false;
}
}
console.log(isValidBase64("SGVsbG8=")); // true
console.log(isValidBase64("!!!bad!!!")); // falseよくある質問
以下を検索するか、よくある質問をご覧ください。
Base64文字列は、許可されたアルファベット(A-Z、a-z、0-9、+、/)以外の文字が含まれている、パディング(=)が正しくない、または長さが4の倍数でない場合(標準Base64の場合)に無効になります。
バリデーターは何が問題かを正確に伝えます。自動修正が必要な場合は、欠落しているパディングを追加し不正な文字を除去できる「Base64修復ツール」をご使用ください。