H hanyelmehy Well-Known Member Licensed User Longtime User Dec 25, 2019 #1 any idea about best way to Validate a URL / Website to avoid errors before useing HttpJob something like Code: private boolean isValidUrl(String url) { Pattern p = Patterns.WEB_URL; Matcher m = p.matcher(url.toLowerCase()); if(m.matches()) return true; else return false; }
any idea about best way to Validate a URL / Website to avoid errors before useing HttpJob something like Code: private boolean isValidUrl(String url) { Pattern p = Patterns.WEB_URL; Matcher m = p.matcher(url.toLowerCase()); if(m.matches()) return true; else return false; }
Erel B4X founder Staff member Licensed User Longtime User Dec 27, 2019 #2 Code: Sub IsUrl (s As String) As Boolean Return Regex.IsMatch("https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)", s) End Sub Source: https://stackoverflow.com/a/3809435/971547 Upvote 0
Code: Sub IsUrl (s As String) As Boolean Return Regex.IsMatch("https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)", s) End Sub Source: https://stackoverflow.com/a/3809435/971547
udg Expert Licensed User Longtime User Dec 27, 2019 #3 Just googling for "regex url validate" gives back a few interesting results. A couple of them (no special reason to select them): In search of the perfect URL validation regex Index of / Edit: Erel was quicker than me (once more eheh) Upvote 0
Just googling for "regex url validate" gives back a few interesting results. A couple of them (no special reason to select them): In search of the perfect URL validation regex Index of / Edit: Erel was quicker than me (once more eheh)
peacemaker Expert Licensed User Longtime User Jan 28, 2020 #4 So many regexp variants on the internet, and each does not cover something... I have made for me: B4X: Sub IsUrl (s As String) As Boolean If s.Trim = "" Then Return False If s.Length < 9 Then Return False If s.ToLowerCase.StartsWith("http") = False Then Return False 'update as needed for you If s.Contains(".") = False Then Return False If s.Contains(":/") = False Then Return False If s.Contains("//") = False Then Return False Return True End Sub Upvote 0
So many regexp variants on the internet, and each does not cover something... I have made for me: B4X: Sub IsUrl (s As String) As Boolean If s.Trim = "" Then Return False If s.Length < 9 Then Return False If s.ToLowerCase.StartsWith("http") = False Then Return False 'update as needed for you If s.Contains(".") = False Then Return False If s.Contains(":/") = False Then Return False If s.Contains("//") = False Then Return False Return True End Sub