Mofeoluwa

Web URL Validator

May 7th, 2020
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.53 KB | None | 0 0
  1. import re
  2. web_address = input('Enter the website url: ')
  3. def validator(web_address):
  4.     '''Function to validate an website address given certain conditions it must meet before it is called valid'''
  5.     try:
  6.         pattern = re.compile(r'^(http://|https://)?[www\.]?[a-zA-Z0-9_.-]+\.[a-z]+$')
  7.         if re.search(pattern,web_address):
  8.             return 'The website url is valid'
  9.         else:
  10.             return 'The website url is invalid'
  11.     except:
  12.         return 'Only strings are allowed'
  13. print(validator(web_address))
Add Comment
Please, Sign In to add comment