The isBase64
function checks if the input string is a valid Base64 string. It returns true
if the string is a valid Base64, and false
otherwise.
The function can be imported using ES6 syntax from the "multiform-validator" package:
import { isBase64 } from 'multiform-validator';
Alternatively, you can import the function using CommonJS syntax with require
(Node.js):
const { isBase64 } = require('multiform-validator');
The function takes one parameter:
value
(string) - The input string to check if it is a valid Base64 string.// Example 1 - Checking if the string is a valid Base64
const result1 = isBase64('SGVsbG8gV29ybGQh');
console.log(result1); // true
// Example 2 - Checking a non-Base64 string
const result2 = isBase64('こんにちは');
console.log(result2); // false
// Example 3 - Checking a non-Base64 string with digits
const result3 = isBase64('12345');
console.log(result3); // false
// Example 4 - Checking a null value
const result4 = isBase64(null);
console.log(result4); // false
The function expects the input value to be passed as a string. It checks if the string is a valid Base64 string using a regular expression. If the input is not a string or an empty string, it throws an error.