1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【JavaScript】文字列がBase64か検証する方法

Posted at

以下のようにすると文字列がBase64か検証できます。

const base64Regex =
  /^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/
  
console.log(base64Regex.test("SomeStringObviouslyNotBase64Encoded...")) // false
console.log(base64Regex.test("U29tZVN0cmluZ09idmlvdXNseU5vdEJhc2U2NEVuY29kZWQ=")) // true
console.log(base64Regex.test("SGVsbG8gV29ybGQ=")) // true
console.log(base64Regex.test("InvalidBase64String!@#")) // false
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?