Skip to main content

A Python Library with various functions to validate user input

Project description

inputvalidate

PyPI - Downloads PyPI - Version

Do you always find yourself having to write extra code every project to validate the input given by users? Then use inputvalidate - a Python package containing various functions to validate user input.

Calvin Chan calvinchan4370z@gmail.com MIT License


Example Usage

Code:

from inputvalidate import get_int

user_age = get_int('Your age (0-99 yrs): ', min=0, max=99)
print(f'You are {user_age} years old.')

Terminal:

Your age (0-99 yrs): twelve
Your age (0-99 yrs): 20.5
Your age (0-99 yrs): -2
Your age (0-99 yrs): 16
You are 16 years old.
$ |

Functions

get_int

get_int(prompt, **kwargs)

Prompts user for an input, expecting an int. Repeats until an int is properly inputted, then returns the int.

kwargs:

  • min: Set min value acceptable
  • max: Set max value acceptable

get_float

get_float(prompt, **kwargs)

Prompts user for an input, expecting a float. Repeats until a number is properly inputted, then returns the input as a float.

kwargs:

  • min: Set min value acceptable
  • max: Set max value acceptable

get_number

get_number(prompt, **kwargs)

Prompts user for a number. Repeats until a number is properly inputted, then returns the input as an int/float, depending on what was inputted.

kwargs:

  • min: Set min value acceptable
  • max: Set max value acceptable

get_string

get_string(prompt, **kwargs)

Prompts user for an input, expecting a string. Repeats until an string is properly inputted, then returns the string

kwargs:

  • min: Set min length acceptable
  • max: Set max length acceptable
  • nospace: Set to True if input must contain no spaces. Default: False

get_bool

get_bool(prompt)

Prompts user for a True/False answer. Repeats until user inputs True or False, ignoring caps, then returns True or False

get_yesno

get_yesno(prompt)

Prompts user for a yes/no answer. Repeats until the first letter of the input is y/n, ignoring caps, then returns 'y' / 'n'

Aliases:

  • get_yn

get_tf

get_tf(prompt)

Prompts user for a t/f answer. Repeats until the first letter of the input is t/f, ignoring caps, then returns 't' / 'f'

get_word

get_word(prompt)

Prompts user for a single word of only alphabet letters. Repeats until a word is properly inputted, then returns the word as a string

get_char

get_char(prompt)

Prompts user for a single ASCII character. Repeats until a character is properly inputted, then returns the char as a string

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

inputvalidate-0.1.8.tar.gz (6.4 kB view details)

Uploaded Source

Built Distribution

inputvalidate-0.1.8-py3-none-any.whl (6.3 kB view details)

Uploaded Python 3

File details

Details for the file inputvalidate-0.1.8.tar.gz.

File metadata

  • Download URL: inputvalidate-0.1.8.tar.gz
  • Upload date:
  • Size: 6.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.12.1

File hashes

Hashes for inputvalidate-0.1.8.tar.gz
Algorithm Hash digest
SHA256 b4ea41200a065d546ea8d92c2107579c3944f858cba948392959a075c29002ce
MD5 c01579c82864c066b41961551a0e5d90
BLAKE2b-256 97e04c4a13c2d29c94a7ed48c4d52907036d3bd83c52f1ba247a21cce8e3a587

See more details on using hashes here.

File details

Details for the file inputvalidate-0.1.8-py3-none-any.whl.

File metadata

File hashes

Hashes for inputvalidate-0.1.8-py3-none-any.whl
Algorithm Hash digest
SHA256 1fa00b5921c4d71d00ba0d03396a2ffc4f79fef10ed8ea0d4e4c7213d638f85a
MD5 7e599a5f63d06561c91fafd02f23b2e8
BLAKE2b-256 e51f51d4f93b744fb69b3ab1a50af1fc5894583f7aa6e016e3b66db5752dca00

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page