Julia Base64 encode and strict decode

Julia
using Base64

function b64decode(text::AbstractString)
    cleaned = replace(text, r"\s+" => "")
    occursin(r"^[A-Za-z0-9+/]*={0,2}$", cleaned) ||
        throw(ArgumentError("invalid Base64 characters"))
    length(cleaned) % 4 == 0 ||
        throw(ArgumentError("Base64 length must be a multiple of 4"))
    try
        return base64decode(cleaned)
    catch err
        throw(ArgumentError("invalid Base64: $(sprint(showerror, err))"))
    end
end

encoded = base64encode("hello julia")
println(encoded, " -> ", String(b64decode(encoded)))