Results 1 to 10 of 10

Thread: How to check that a string is a proper URL

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2007
    Posts
    544

    How to check that a string is a proper URL

    That starts with http://

    Using regular expression

    Can I see a code

    Thanks

  2. #2

  3. #3
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: How to check that a string is a proper URL

    How about something simple like
    Code:
    If Left(Text1.Text, 7) <> "http://" Then
       MsgBox "Invalid URL"
    End If

  4. #4
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: How to check that a string is a proper URL

    Why user regex when its simple to use string functions like hack posted?

    What are the reqquirements for the urls? "https://", "ftp://", "ftps://" etc?
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  5. #5

  6. #6

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2007
    Posts
    544

    Re: How to check that a string is a proper URL

    Well because I have 10000 URL to check and I want to do it quickly. Surfing them one by one is not a good idea.

    Doesn't have to be regex but regex seems to be the way to go.

    Let's see we can make sure it has only one http:// or https://

    Then we look at the content between http:// and the next /

    Then we look that those between and after that consists of numbers and letters allowed in a URL

    There has to be regex for this one already.

  7. #7
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629

    Re: How to check that a string is a proper URL

    Check left side as already mentioned. Check if there are unescaped characters, e.g. spaces instead of %20. URL may then be syntactically valid... but real validity can only be tested by navigation.

  8. #8
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: How to check that a string is a proper URL

    Well what is it that you want to accomplish? Check for valid syntax only or check for valid syntax and know the url points to a valid site?
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  9. #9

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2007
    Posts
    544

    Re: How to check that a string is a proper URL

    Only valid syntax.

    Of course the only way to know that the URL is valid is by actually visiting the URL.

    No. Just valid syntax.

  10. #10
    VB6, XHTML & CSS hobbyist Merri's Avatar
    Join Date
    Oct 2002
    Location
    Finland
    Posts
    6,654

    Re: How to check that a string is a proper URL


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width