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 hashes)

Uploaded Source

Built Distribution

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

Uploaded Python 3

Supported by

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