SkillAgentSearch skills...

Py.validator

Package that allows for validate and sanitize of string values. For example to check if a string is an ascii string etc.

Install / Use

/learn @theteladras/Py.validator
About this skill

Quality Score

0/100

Supported Platforms

Universal

README

py.validator

A library of string validators and sanitizers

Insipired by validator.js

Strings only

This library validates and sanitizes strings only.

Passing anything other than a string will result in an error.

Instalation

You can install it by running: pip install py.validator

Usage

from pyvalidator import is_email, is_mobile_number, is_port

email = 'some@email.com'

is_email_flag = is_email(email)

mobile_number = '+15673628910'

is_mobile_number_flag = is_mobile_number(mobile_number)

port = '8000'

is_port_flag = is_port(port)

if is_email_flag and is_mobile_number_flag and is_port_flag:
    print('All True!')

Validators

Here is a list of the validators currently available.

Validator | Description --------------------------------------- | -------------------------------------- is_after(str, date) | check if the string is a date that's after the specified argument date (defaults to now if not provided). is_alpha(str, locale, options) | check if the string contains only letters (a-zA-Z).<br/><br/>Locale is one of ['ar', 'ar-AE', 'ar-BH', 'ar-DZ', 'ar-EG', 'ar-IQ', 'ar-JO', 'ar-KW', 'ar-LB', 'ar-LY', 'ar-MA', 'ar-QA', 'ar-QM', 'ar-SA', 'ar-SD', 'ar-SY', 'ar-TN', 'ar-YE', 'bg-BG', 'cs-CZ', 'da-DK', 'de-DE', 'el-GR', 'en-AU', 'en-GB', 'en-HK', 'en-IN', 'en-NZ', 'en-US', 'en-ZA', 'en-ZM', 'es-ES', 'fa-IR', 'fi-FI', 'fr-CA', 'fr-FR', 'he', 'hi-IN', 'hu-HU', 'it-IT', 'ku-IQ', 'nb-NO', 'nl-NL', 'nn-NO', 'pl-PL', 'pt-BR', 'pt-PT', 'ru-RU', 'sl-SI', 'sk-SK', 'sr-RS', 'sr-RS@latin', 'sv-SE', 'tr-TR', 'uk-UA']) and defaults to en-US. The locale list can be picked up from validator.locales. Options is an optional dictionary that can be supplied with the following key(s): ignore which can either be a String or RegExp of characters to be ignored e.g. " -" will ignore spaces and -'s. is_alphanumeric(str, locale, options) | check if the string contains only letters and numbers (a-zA-Z0-9).<br/><br/>Locale is one of ['ar', 'ar-AE', 'ar-BH', 'ar-DZ', 'ar-EG', 'ar-IQ', 'ar-JO', 'ar-KW', 'ar-LB', 'ar-LY', 'ar-MA', 'ar-QA', 'ar-QM', 'ar-SA', 'ar-SD', 'ar-SY', 'ar-TN', 'ar-YE', 'bg-BG', 'cs-CZ', 'da-DK', 'de-DE', 'el-GR', 'en-AU', 'en-GB', 'en-HK', 'en-IN', 'en-NZ', 'en-US', 'en-ZA', 'en-ZM', 'es-ES', 'fa-IR', 'fi-FI', 'fr-CA', 'fr-FR', 'he', 'hi-IN', 'hu-HU', 'it-IT', 'ku-IQ', 'nb-NO', 'nl-NL', 'nn-NO', 'pl-PL', 'pt-BR', 'pt-PT', 'ru-RU', 'sl-SI', 'sk-SK', 'sr-RS', 'sr-RS@latin', 'sv-SE', 'tr-TR', 'uk-UA']) and defaults to en-US. The locale list can be picked up from validator.locales. options is an optional dictionary that can be supplied with the following key(s): ignore which can either be a String or RegExp of characters to be ignored e.g. " -" will ignore spaces and -'s. is_ascii(str) | check if the string contains ASCII chars only. is_aws_arn(str, resource) | check if the string is a valid amazon resource name. Supported resources are ['connect', 'iam', 'orgs', 'ecs', 'ec2', 'lambda', 's3', 'sts', 'sqs']. You may provide a second argument to be more specific with the resource for which the validation should be done. This are the options:<br/> - connect <br/> - iam <br/> - iam-user <br/> - iam-group <br/> - iam-role <br/> - iam-policy <br/> - orgs <br/> - orgs-account <br/> - orgs-handshake <br/> - orgs-org <br/> - org-unit <br/> - ecs <br/> - ecs-instance <br/> - ecs-service <br/> - ec2 <br/> - lambda <br/> - lambda-function <br/> - lambda-event-mapping <br/> - lambda-layer <br/> - s3 <br/> - sts <br/> - sqs is_base32(str) | check if a string is base32 encoded. is_base58(str) | check if a string is base58 encoded. is_base64(str, options) | check if a string is base64 encoded. options is optional and defaults to { "url_safe": False }<br/> when url_safe is True it tests the given base64 encoded string is url safe. is_before(str, date) | check if the string is a date that's before the specified date. is_bic(str) | check if a string is a BIC (Bank Identification Code) or SWIFT code. is_boolean(str, options) | check if a string is a boolean.<br/>options is an dictionary which defaults to { "loose": False }. If loose is is set to false, the validator will strictly match ['True', 'False', 'true', 'false', '0', '1']. If loose is set to true, the validator will also match yes, no, and will match a valid boolean string of any case (eg: ['true', 'True', 'TRUE']). is_btc_address(str) | check if the string is a valid BTC address. is_byte_length(str, options) | check if the string's length (in UTF-8 bytes) falls in a range.<br/><br/>options is an dictionary which defaults to { "min": 0, "max": None }. is_credit_card(str) | check if the string is a credit card. is_css_unit(str) | check if the string is a css unit (eg. 3px, 3vh, 11%...), 0 without a unit is considered as valid. is_currency(str, options) | check if the string is a valid currency amount.<br/><br/>options is an optional dictionary which is defaultet to:<br/>{ <br/>    "symbol": '$', <br/>    "require_symbol": False, <br/>    "allow_space_after_symbol": False, <br/>    "symbol_after_digits": False, <br/>    "allow_negatives": True, <br/>    "parens_for_negatives": False, <br/>    "negative_sign_before_digits": False, <br/>    "negative_sign_after_digits": False, <br/>    "allow_negative_sign_placeholder": False, <br/>    "thousands_separator": ',', <br/>    "decimal_separator": '.', <br/>    "allow_decimal": True, <br/>    "require_decimal": False, <br/>    "digits_after_decimal": [2], <br/>    "allow_space_after_digits": False <br/>} <br/>Note: The array digits_after_decimal is filled with the exact number of digits allowed not a range, for example a range 1 to 3 will be given as [1, 2, 3]. is_data_uri(str) | check if the string is a data uri format. is_date(str, options) | Check if the input is a valid date. e.g. [2002-07-15, new Date()].<br/><br/> options is an optional dictionary which can contain the keys format, strict_mode and/or delimiters<br/><br/>format is a string and defaults to YYYY/MM/DD.<br/><br/>strict_mode is a boolean and defaults to False. If strict_mode is set to True, the validator will reject inputs different from format.<br/><br/> delimiters is an array of allowed date delimiters and defaults to ['/', '-'], supported delimiters are ['/', '-', '.', ',', ';', ':', '\|' ]. is_decimal(str, options) | check if the string represents a decimal number, such as 0.1, .3, 1.1, 1.00003, 4.0, etc.<br/><br/>options is an dictionary which defaults to { "force_decimal": False, "decimal_digits": '1,', "locale": 'en-US' }<br/><br/>locale determine the decimal separator and is one of ['ar', 'ar-AE', 'ar-BH', 'ar-DZ', 'ar-EG', 'ar-IQ', 'ar-JO', 'ar-KW', 'ar-LB', 'ar-LY', 'ar-MA', 'ar-QA', 'ar-QM', 'ar-SA', 'ar-SD', 'ar-SY', 'ar-TN', 'ar-YE', 'bg-BG', 'cs-CZ', 'da-DK', 'de-DE', 'el-GR', 'en-AU', 'en-GB', 'en-HK', 'en-IN', 'en-NZ', 'en-US', 'en-ZA', 'en-ZM', 'es-ES', 'fa', 'fa-AF', 'fa-IR', 'fr-FR', 'fr-CA', 'hu-HU', 'id-ID', 'it-IT', 'ku-IQ', 'nb-NO', 'nl-NL', 'nn-NO', 'pl-PL', 'pl-Pl', 'pt-BR', 'pt-PT', 'ru-RU', 'sl-SI', 'sr-RS', 'sr-RS@latin', 'sv-SE', 'tr-TR', 'uk-UA', 'vi-VN'].<br/>Note: decimal_digits is given as a range like '1,3', a specific value like '3' or min like '1,'. is_divisible_by(str, number) | check if the string is a number that's divisible by another. is_ean(str) | check if the string is an EAN (European Article Number). is_email(str, options) | check if the string is an email.<br/><br/>options is an dictionary which defaults to { "allow_display_name": False, "require_display_name": False, "allow_utf8_local_part": True, "require_tld": True, "allow_ip_domain": False, "domain_specific_validation": False, "ignore_max_length": False, "blacklisted_chars": '', "host_blacklist": [] }. If allow_display_name is set to True, the validator will also match Display Name <email-address>. If require_display_name is set to True, the validator will reject strings without the format Display Name <email-address>. If allow_utf8_local_part is set to False, the validator will not allow any non-English UTF8 character in email address' local part. If require_tld is set to False, e-mail addresses without having TLD in their domain will also be matched. If ignore_max_length is set to True, the validator will not check for the standard max length of an email. If allow_ip_domain is set to True, the validator will allow IP addresses in the host part. If domain_specific_validation is True, some additional validation will be enabled, e.g. disallowing certain syntactically valid email addresses that are rejected by GMail. If blacklisted_chars receives a string, then the validator will reject emails that include any of the characters in the string, in the name part. If host_blacklist is set to an array of strings and the part of the email after the @ symbol matches one of the strings defined in it, the validation fails. is_emoji(str, options) | check if the provided string is a valid emoji. A string of length grater then 1, is considered as a valid emoji if all of its characters are emoji characters, for example '🍗🍗🍗' is valid, while '🍗@🍗🍗' would

Related Skills

View on GitHub
GitHub Stars23
CategoryDevelopment
Updated1y ago
Forks3

Languages

Python

Security Score

75/100

Audited on Oct 30, 2024

No findings