Android Code Snippet Check if a string is Base64 (isBase64)

Discussion in 'Code Snippets' started by Douglas Farias, Oct 19, 2018.

  1. Douglas Farias

    Douglas Farias Expert Licensed User

    Hi all.
    I found this example in some old folders on my pc and decided to share here.
    it is a simple code to check if a string is base64 hash.

    This example use a regex.

    Sub isBase64(text As StringAs Boolean
    If Regex.IsMatch("^([A-Za-z0-9+/]{4})*([A-Za-z0-9+/]{4}|[A-Za-z0-9+/]{3}=|[A-Za-z0-9+/]{2}==)$", text.Trim) And text.Length > 3  Then
    Return True
    Return False
    End If
    End Sub

    Example of use
        Log(isBase64("ZG91Z2xhc2Zhcmlhcw==")) '=douglasfarias
        Log(isBase64("Test string"))'=dont is a base64 string

    The result log is

    Credits: stackoverflow, Douglas Farias and Flavio Rocha

    Attached Files:

    Last edited: Dec 2, 2018
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice