Android Question Validate a URL / Website name in EditText

hanyelmehy

Active Member
Licensed User
Longtime User
any idea about best way to Validate a URL / Website to avoid errors before useing HttpJob
something like
B4X:
private boolean isValidUrl(String url) {
      Pattern p = Patterns.WEB_URL;
      Matcher m = p.matcher(url.toLowerCase());
      if(m.matches())
         return true;
      else
        return false;
}
 

udg

Expert
Licensed User
Longtime User
Upvote 0

peacemaker

Expert
Licensed User
Longtime User
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

udg

Expert
Licensed User
Longtime User
So http..://../anything is ok?
 
Upvote 0
Top