100% Client-Side β’ 0 B Data Leaves Browser
validation
Base64 Encoded String Validation Regex
Validates standard RFC 4648 Base64 encoded strings with valid length multiples of 4 and padding.
Regular Expression Pattern:
/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/
Valid Match Example:
SGVsbG8gV29ybGQh
Invalid / Non-Match Example:
Invalid Base64 string==
Regex Syntax Breakdown & Explanation
- β’(?:[A-Za-z0-9+/]{4})* : Matches multiples of 4 base64 characters
- β’(?:...==|...=)? : Validates 0, 1, or 2 trailing padding equals signs
Implementation in Popular Languages
JavaScript / TypeScript
const regex = /^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/;
const isValid = regex.test("SGVsbG8gV29ybGQh");
console.log(isValid); // truePython (re)
import re
pattern = r"^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$"
match = re.match(pattern, "SGVsbG8gV29ybGQh")
print(bool(match)) # TrueGo (regexp)
package main
import (
"fmt"
"regexp"
)
func main() {
re := regexp.MustCompile(`^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$`)
fmt.Println(re.MatchString("SGVsbG8gV29ybGQh"))
}Frequently Asked Questions
Frequently Asked Questions
Everything you need to know regarding specifications, syntax, and security best practices.
The regular expression pattern is /^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/. Validates standard RFC 4648 Base64 encoded strings with valid length multiples of 4 and padding.