0

I'm struggling to even ask this question properly. I need to create a validation formula in Python.

Needs to verify that a URL is entered with:

  1. http:// or 2. https:// with 3. full FQDN (mysite.domain.toplevel or www.mysite.domain.toplevel as in www.mysite.com or mysite.google.com or even www.mysite.mysite2.google.com)

So basically the input validation needs to check if it is http:// or https:// ONLY. Then if it has at least two periods, but could be three or four. Minimum is two.

Does this make sense to anyone? Using try and except along with Stringtolower has been suggested, but I don't understand how to verify that the input field has these above pieces.

EDIT: Both of the suggested solutions are nowhere close to being readable or reasonable. The links answers at the link suggeste deprecated modules, or disprove the answer.

Examples-

verify_exists is deprecated for security reasons and has been removed in Django 1.5 – Yohann Apr 12 '13 at 15:57

Jonathan is right. I agree that validation isn't easy, but urlparse does zero validation. There's a wide range of very invalid strings which urlparse happily pretends to parse. such as "::::::::::" which any browser would reject. Surely there's a better lib out there for checking some of the basic requirements of a URL. – Swarf May 26 '15 at 23:42

Someone else mentions "Here's the complete regexp to parse a URL."

How does this answer my questions? The answer is unclear.

DjIns1ght
  • 13
  • 4
  • 2
    Possible duplicate of [Python - How to validate a url in python ? (Malformed or not)](https://stackoverflow.com/questions/7160737/python-how-to-validate-a-url-in-python-malformed-or-not) – Gelineau Oct 01 '19 at 20:34
  • Possible duplicate of [How do you validate a URL with a regular expression in Python?](https://stackoverflow.com/questions/827557/how-do-you-validate-a-url-with-a-regular-expression-in-python) – mkrieger1 Oct 01 '19 at 21:00

0 Answers0