Android Question Valid URL

Robert Valentino

Well-Known Member
Licensed User
Longtime User
I tried Erels code (https://www.b4x.com/android/forum/threads/validate-a-url-website-name-in-edittext.112478/) for checking for a valid URL

The one I was checking is this

So I made the following changes to the routine
IsValidUrl:
Sub IsValidUrl(Url As String) As Boolean
    Dim Pattern As String = $"https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)"$
    Return Regex.IsMatch(Pattern, Url)
End Sub

NOT sure if it will handle everything. But mostly I am checking file names and it works for them
 
Top