Skip to content

Easy Validator

py_simple.easy_validator

easy_validator is built to simplify validation.

is_password_secure(password)

Returns true if password is valid.

Validation checks
  • minimum length of 8 characters
  • at least one special character
  • at least one upper case letter
  • at least two lowercase letters
  • at least two digits
  • no repeating characters

Parameters:

Name Type Description Default
password str

password to validate.

required

Returns:

Name Type Description
bool bool

True if the password meets all checks, False otherwise.

Example
from py_simple import is_password_secure

result = is_password_secure("1andkrf!AG5")  # -> True
from string import punctuation

password = "1andkrf!AG5"
min_length = 8
upper_letters = 0
lower_letters = 0
digits = 0
special_characters = 0
last_char = ''
result = False

if len(password) > min_length:
    for char in password:
        if char.isdigit():
            digits += 1
            if char == last_char:
                result = False
                break
            last_char = char
        elif char.isalpha():
            if char.upper() == char:
                upper_letters += 1
                if char == last_char:
                    result = False
                    break
                last_char = char
            elif char.lower() == char:
                lower_letters += 1
                if char == last_char:
                    result = False
                    break
                last_char = char
        elif char in punctuation:
            special_characters += 1
            if char == last_char:
                result = False
                break
            last_char = char
    else:
        result = (
            upper_letters >= 1 and lower_letters >= 2 and
            digits >= 2 and special_characters >= 1
        )

is_valid_email(email)

Returns true if email is valid.

Parameters:

Name Type Description Default
email str

email address to validate.

required

Returns:

Name Type Description
bool bool

True if the email is valid, False otherwise.

Example
from py_simple import is_valid_email

if is_valid_email("hello@world.com"):
    print("Looks good!")
import re

pattern = r'[a-zA-Z_.%+-]+@[a-zA-Z0-9-]+\.[a-zA-Z]+'
if re.fullmatch(pattern, "hello@world.com"):
    print("Looks good!")

is_valid_url(url)

Returns true if url is valid.

Parameters:

Name Type Description Default
url str

URL to validate.

required

Returns:

Name Type Description
bool bool

True if the URL is valid, False otherwise.

Example
from py_simple import is_valid_url

result = is_valid_url("www.google.com")  # -> True
import re

pattern = (r'(?:https?://(?:www\.)?|www\.)[a-zA-Z0-9-]+\.'
   r'(?:(?:[a-zA-Z0-9-]+\.)*)?(?:(?:[a-zA-Z0-9-]+\)*)'
   r'?[a-zA-Z]{2,}(?:\.[a-zA-Z]{2,})?(?:/\S*)?')
result = bool(re.fullmatch(pattern, "www.google.com"))

is_valid_username(username)

Returns true if username is valid.

Parameters:

Name Type Description Default
username str

username to validate.

required

Returns:

Name Type Description
bool bool

True if the username is valid, False otherwise.

Example
from py_simple import is_valid_username

result = is_valid_username("user_name")  # -> True
import re

pattern = r'^[a-zA-Z0-9_]+'
result = bool(re.fullmatch(pattern, "user_name"))

is_valid_zipcode(zipcode)

Returns true if US zip code is valid.

Parameters:

Name Type Description Default
zipcode int

US zipcode to validate.

required

Returns:

Name Type Description
bool bool

True if the zip code is valid, False otherwise.

Example
from py_simple import is_valid_zipcode

result = is_valid_zipcode(12345)  # -> True
import re

pattern = r'^[0-9]{5}$'
result = bool(re.fullmatch(pattern, str(12345)))