Usage

Basic Validation

Each validator in validus is a simple function that takes the value to validate and possibly some additional key-value arguments. Each function returns True when validation succeeds and False when validation fails.

Basic Usage

>>> import validus
>>> validus.isemail('me@mine.com')
True
>>> validus.isemail('@invalid.com')
False

Available Functions

isascii

validus.isascii(value)[source]

Return whether or not given value contains ASCII chars only. Empty string is valid. If the value contains ASCII chars only, this function returns True, otherwise False.

Examples:

>>> isascii('1234abcDEF')
True

>>> isascii('foobar')
False
Parameters:value – string to validate ASCII chars

isprintascii

validus.isprintascii(value)[source]

Return whether or not given value contains printable ASCII chars only. Empty string is valid. If the value contains printable ASCII chars only, this function returns True, otherwise False.

Examples:

>>> isprintascii('1234abcDEF')
True

>>> isprintascii('foobar')
False
Parameters:value – string to validate printable ASCII chars

isnonempty

validus.isnonempty(value)[source]

Return whether the value is not empty

Examples:

>>> isnonempty('a')
True

>>> isnonempty('')
False
Parameters:value – string to validate whether value is not empty

isbase64

validus.isbase64(value)[source]

Return whether or not given value is base64 encoded. If the value is base64 encoded, this function returns True, otherwise False.

Examples:

>>> isbase64('U3VzcGVuZGlzc2UgbGVjdHVzIGxlbw==')
True

>>> isbase64('Vml2YW11cyBmZXJtZtesting123')
False
Parameters:value – string to validate base64 encoding

isemail

validus.isemail(value)[source]

Return whether or not given value is an email. If the value is an email, this function returns True, otherwise False.

Examples:

>>> isemail('foo@bar.com')
True

>>> isemail('invalidemail@')
False
Parameters:value – string to validate email

ishexadecimal

validus.ishexadecimal(value)[source]

Return whether or not given value is a hexadecimal number. If the value is a hexadecimal number, this function returns True, otherwise False.

Examples:

>>> ishexadecimal('deadBEEF')
True

>>> ishexadecimal('abcdefg')
False
Parameters:value – string to validate hexadecimal number

ishexcolor

validus.ishexcolor(value)[source]

Return whether or not given value is a hexadecimal color. If the value is a hexadecimal color, this function returns True, otherwise False.

Examples:

>>> ishexcolor('#ff0034')
True

>>> ishexcolor('#ff12FG')
False
Parameters:value – string to validate hexadecimal color

isrgbcolor

validus.isrgbcolor(value)[source]

Return whether or not given value is a rgb color. If the value is a rgb color, this function returns True, otherwise False.

Examples:

>>> isrgbcolor('rgb(0,31,255)')
True

>>> isrgbcolor('rgb(1,349,275)')
False
Parameters:value – string to validate rgb color

isint

validus.isint(value)[source]

Return whether or not given value is an integer. If the value is an integer, this function returns True, otherwise False.

Examples:

>>> isint('-2147483648')
True

>>> isint('123.123')
False
Parameters:value – string to validate integer

isfloat

validus.isfloat(value)[source]

Return whether or not given value is a float. This does not give the same answer as:

isinstance(num_value,float)

Because isfloat(‘1’) returns true. More strict typing requirements may want to use is_instance.

If the value is a float, this function returns True, otherwise False.

Examples:

>>> isfloat('01.123')
True

>>> isfloat('+1f')
False
Parameters:value – string to validate float

isslug

validus.isslug(value)[source]

Validate whether or not given value is valid slug. Valid slug can contain only alphanumeric characters, hyphens and underscores. If the value is a slug, this function returns True, otherwise False.

Examples:

>>> isslug('my-slug-2134')
True

>>> isslug('my.slug')
False
Parameters:value – value to validate

isuuid

validus.isuuid(value)[source]

Return whether or not given value is a UUID (version 3, 4 or 5). If the value is a UUID (version 3, 4 or 5), this function returns True, otherwise False.

Examples:

>>> isuuid('a987fbc9-4bed-3078-cf07-9141ba07c9f3')
True

>>> isuuid('xxxA987FBC9-4BED-3078-CF07-9141BA07C9F3')
False
Parameters:value – string to validate UUID (version 3, 4 or 5)

isuuid3

validus.isuuid3(value)[source]

Return whether or not given value is a UUID version 3. If the value is a UUID version 3, this function returns True, otherwise False.

Examples:

>>> isuuid3('A987FBC9-4BED-3078-CF07-9141BA07C9F3')
True

>>> isuuid3('xxxA987FBC9-4BED-3078-CF07-9141BA07C9F3')
False
Parameters:value – string to validate UUID version 3

isuuid4

validus.isuuid4(value)[source]

Return whether or not given value is a UUID version 4. If the value is a UUID version 4, this function returns True, otherwise False.

Examples:

>>> isuuid4('713ae7e3-cb32-45f9-adcb-7c4fa86b90c1')
True

>>> isuuid4('A987FBC9-4BED-3078-CF07-9141BA07C9F3')
False
Parameters:value – string to validate UUID version 4

isuuid5

validus.isuuid5(value)[source]

Return whether or not given value is a UUID version 5. If the value is a UUID version 5, this function returns True, otherwise False.

Examples:

>>> isuuid5('987FBC97-4BED-5078-AF07-9141BA07C9F3')
True

>>> isuuid5('9c858901-8a57-4791-81fe-4c455b099bc9')
False
Parameters:value – string to validate UUID version 5

isfullwidth

validus.isfullwidth(value)[source]

Return whether or not given value contains any full-width chars. If the value contains any full-width chars, this function returns True, otherwise False.

Examples:

>>> isfullwidth('3ー0 a@com')
True

>>> isfullwidth('abc123')
False
Parameters:value – string to validate full-width chars

ishalfwidth

validus.ishalfwidth(value)[source]

Return whether or not given value contains any half-width chars. If the value contains any half-width chars, this function returns True, otherwise False.

Examples:

>>> ishalfwidth('l-btn_02--active')
True

>>> ishalfwidth('0011')
False
Parameters:value – string to validate half-width chars

islatitude

validus.islatitude(value)[source]

Return whether or not given value is valid latitude. If the value is valid latitude, this function returns True, otherwise False.

Examples:

>>> islatitude('-90.000')
True

>>> islatitude('+99.9')
False
Parameters:value – string to validate latitude

islongitude

validus.islongitude(value)[source]

Return whether or not given value is valid longitude. If the value is valid longitude, this function returns True, otherwise False.

Examples:

>>> islongitude('+73.234')
True

>>> islongitude('180.1')
False
Parameters:value – string to validate longitude

ismac

validus.ismac(value)[source]

Return whether or not given value is valid MAC address. If the value is valid MAC address, this function returns True, otherwise False.

Examples:

>>> ismac('3D:F2:C9:A6:B3:4F')
True

>>> ismac('01:02:03:04:05')
False
Parameters:value – string to validate MAC address

ismd5

validus.ismd5(value)[source]

Return whether or not given value is MD5 encoded. If the value is MD5 encoded, this function returns True, otherwise False.

Examples:

>>> ismd5('d94f3f016ae679c3008de268209132f2')
True

>>> ismd5('KYT0bf1c35032a71a14c2f719e5a14c1')
False
Parameters:value – string to validate MD5 encoding

ismongoid

validus.ismongoid(value)[source]

Return whether or not given value is a valid hex-encoded representation of a MongoDB ObjectId. If the value is a MongoDB ObjectId, this function returns True, otherwise False.

Examples:

>>> ismongoid('507f1f77bcf86cd799439011')
True

>>> ismongoid('507f1f77bcf86cd7994390')
False
Parameters:value – string to validate MongoDB ObjectId

isiso8601

validus.isiso8601(value)[source]

Return whether or not given value is ISO 8601 date. If the value is ISO 8601 date, this function returns True, otherwise False.

Examples:

>>> isiso8601('2009-12T12:34')
True

>>> isiso8601('2009367')
False
Parameters:value – string to validate ISO 8601 date

isipv4

validus.isipv4(value)[source]

Return whether or not given value is an IP version 4. If the value is an IP version 4, this function returns True, otherwise False.

Examples:

>>> isipv4('127.0.0.1')
True

>>> isipv4('::1')
False
Parameters:value – string to validate IP version 4

isipv6

validus.isipv6(value)[source]

Return whether or not given value is an IP version 6. If the value is an IP version 6, this function returns True, otherwise False.

Examples:

>>> isipv6('2001:41d0:2:a141::1')
True

>>> isipv6('127.0.0.1')
False
Parameters:value – string to validate IP version 6

isip

validus.isip(value)[source]

Return whether or not given value is an IP version 4 or 6. If the value is an IP version 4 or 6, this function returns True, otherwise False.

Examples:

>>> isip('127.0.0.1')
True

>>> isip('0200.200.200.200')
False
Parameters:value – string to validate IP version 4 or 6

isport

validus.isport(value)[source]

Return whether or not given value represents a valid port. If the value represents a valid port, this function returns True, otherwise False.

Examples:

>>> isport('8080')
True

>>> isport('65536')
False
Parameters:value – string to validate port

isdns

validus.isdns(value)[source]

Return whether or not given value represents a valid DNS name. If the value represents a valid DNS name, this function returns True, otherwise False.

Examples:

>>> isdns('localhost')
True

>>> isdns('a.b..')
False
Parameters:value – string to validate DNS name

isssn

validus.isssn(value)[source]

Return whether or not given value is a U.S. Social Security Number. If the value is a U.S. Social Security Number, this function returns True, otherwise False.

Examples:

>>> isssn('191 60 2869')
True

>>> isssn('66690-76')
False
Parameters:value – string to validate U.S. Social Security Number

issemver

validus.issemver(value)[source]

Return whether or not given value is valid semantic version. If the value is valid semantic version, this function returns True, otherwise False.

Examples:

>>> issemver('v1.0.0')
True

>>> issemver('1.1.01')
False
Parameters:value – string to validate semantic version

isbytelen

validus.isbytelen(value, minimum, maximum)[source]

Return whether or not given value’s length (in bytes) falls in a range. If the value’s length (in bytes) falls in a range, this function returns True, otherwise False.

Examples:

>>> isbytelen('123456', 0, 100)
True

>>> isbytelen('1239999', 0, 1)
False
Parameters:
  • value – string to validate length (in bytes) falls in a range
  • minimum – minimum value of the range in integer
  • maximum – maximum value of the range in integer

ismultibyte

validus.ismultibyte(value)[source]

Return whether or not given value contains one or more multibyte chars. If the value contains one or more multibyte chars, this function returns True, otherwise False.

Examples:

>>> ismultibyte('あいうえお foobar')
True

>>> ismultibyte('abc')
False
Parameters:value – string to validate one or more multibyte chars

isfilepath

validus.isfilepath(value)[source]

Return whether or not given value is Win or Unix file path and returns it’s type. If the value is Win or Unix file path, this function returns True, Type, otherwise False, Type.

Examples:

>>> isfilepath('c:\path\file (x86)\bar')
True, 'Win'

>>> isfilepath('/path')
True, 'Unix'

>>> isfilepath('c:/path/file/')
False, 'Unknown'
Parameters:value – string to validate file path

isdatauri

validus.isdatauri(value)[source]

Return whether or not given value is base64 encoded data URI such as an image. If the value is base64 encoded data URI, this function returns True, otherwise False.

Examples:

>>> isdatauri('data:text/plain;base64,Vml2YW11cyBmZXJtZW50dW0gc2VtcGVyIHBvcnRhLg==')
True

>>> isdatauri('dataxbase64data:HelloWorld')
False
Parameters:value – string to validate base64 encoded data URI

isjson

validus.isjson(value)[source]

Return whether or not given value is valid JSON. If the value is valid JSON, this function returns True, otherwise False.

Examples:

>>> isjson('{"Key": {"Key": {"Key": 123}}}')
True

>>> isjson('{ key: "value" }')
False
Parameters:value – string to validate JSON

istime

validus.istime(value, fmt)[source]

Return whether or not given value is valid time according to given format. If the value is valid time, this function returns True, otherwise False.

Examples:

>>> istime('30 Nov 00', '%d %b %y')
True

>>> istime('Friday', '%d')
False
Parameters:
  • value – string to validate time
  • fmt – format of time

isurl

validus.isurl(value)[source]

Return whether or not given value is an URL. If the value is an URL, this function returns True, otherwise False.

Examples:

>>> isurl('http://foo.bar#com')
True

>>> isurl('http://foobar.c_o_m')
False
Parameters:value – string to validate URL

iscrcard

validus.iscrcard(value)[source]

Return whether or not given value is a credit card. If the value is a credit card, this function returns True, otherwise False.

Examples:

>>> iscrcard('375556917985515')
True

>>> iscrcard('5398228707871528')
False
Parameters:value – string to validate credit card

isisin

validus.isisin(value)[source]

Return whether or not given value is valid International Securities Identification Number. If the value is a valid ISIN, this function returns True, otherwise False.

Examples:

>>> isisin('AU0000XVGZA3')
True

>>> isisin('DE000BAY0018')
False
Parameters:value – string to validate ISIN

isiban

validus.isiban(value)[source]

Return whether or not given value is a valid IBAN code. If the value is a valid IBAN, this function returns True, otherwise False.

Examples:

>>> isiban('DE29100500001061045672')
True

>>> isiban('NO9186011117947')
False
Parameters:value – string to validate IBAN code

isphone

validus.isphone(value, locale='en-US')[source]

Return whether or not given value is valid mobile number according to given locale. Default locale is ‘en-US’. If the value is valid mobile number, this function returns True, otherwise False. Supported locales are: ar-DZ, ar-SY, ar-SA, en-US, en-CA, cs-CZ, de-DE, da-DK el-GR, en-AU, en-GB, en-HK, zh-HK, en-IN, en-NG, en-NZ, en-ZA, en-ZM es-ES, fi-FI, fr-FR, he-IL, hu-HU, id-ID, it-IT, ja-JP, ms-MY, nb-NO nl-BE, fr-BE, nn-NO, pl-PL, pt-BR, pt-PT, ro-RO, en-PK, ru-RU, sr-RS tr-TR, vi-VN, zh-CN, zh-TW, bn-BD

Examples:

>>> isphone('+15673628910', 'en-US')
True

>>> isphone('+10345672645', 'en-US')
False
Parameters:
  • value – string to validate mobile number
  • locale – locale of mobile number to validate

isisbn

validus.isisbn(isbn, version=None)[source]

Return whether or not given value is a valid ISBN (version 10 or 13). If version value is not equal to 10 or 13, it will be check both variants. If the value is a valid ISBN this function returns True, otherwise False.

Examples:

>>> isisbn('978-3-8362-2119-1')
True

>>> isisbn('978-3-8362-2119-0')
False
Parameters:
  • isbn – ISBN string to validate
  • version – Optional ISBN version (10 or 13)

isisbn10

validus.isisbn10(isbn)[source]

Return whether or not given value is a valid ISBN version 10. If the value is a valid ISBN version 10 this function returns True, otherwise False.

Examples:

>>> isisbn10('3-401-01319-X')
True

>>> isisbn10('3-423-21412-1')
False
Parameters:isbn – ISBN version 10 string to validate

isisbn13

validus.isisbn13(isbn)[source]

Return whether or not given value is a valid ISBN version 13. If the value is a valid ISBN version 13 this function returns True, otherwise False.

Examples:

>>> isisbn13('978-4-87311-368-5')
True

>>> isisbn13('01234567890ab')
False
Parameters:isbn – ISBN version 13 string to validate

ispositive

validus.ispositive(value)[source]

Return whether a number is positive or not

Examples:

>>> ispositive('1')
True

>>> ispositive('1.')
True

>>> ispositive('-1.')
False

>>> ispositive('a')
False
Parameters:value – string to validate number

isimei

validus.isimei(value)[source]

Return whether or not given value is an imei. If the value is an imei, this function returns True, otherwise False.

Examples:

>>> isimei('565464561111118')
True

>>> isimei('123456789012341')
False
Parameters:value – string to validate imei

issha1

validus.issha1(value)[source]

Return whether or not given value is SHA1 encoded. If the value is SHA1 encoded, this function returns True, otherwise False.

Examples:

>>> issha1('1bc6b8a58b484bdb6aa5264dc554934e3e46c405')
True

>>> issha1('ZKYT059dbf1c356032a7b1a1d4c2f719e5a14c1')
False
Parameters:value – string to validate SHA1 encoding

issha256

validus.issha256(value)[source]

Return whether or not given value is SHA256 encoded. If the value is SHA256 encoded, this function returns True, otherwise False.

Examples:

>>> issha256('fd04c4a99b6b1f118452da33dfe9523ec164f5fecde4502b69f1ed3f24a29ff6')
True

>>> issha256('KLO4545ID55545789Hg545235F4525576adca7676cd7dca7976676e6789dcaee')
False
Parameters:value – string to validate SHA256 encoding

issha512

validus.issha512(value)[source]

Return whether or not given value is SHA512 encoded. If the value is SHA512 encoded, this function returns True, otherwise False.

Examples:

>>> issha512('0b696861da778f6bd0d899ad9a581f4b9b1eb8286eaba266d2f2e2767539055bf8eb59e8884839a268141aba1ef078ce67cf94d421bd1195a3c0e817f5f7b286')
True

>>> issha512('KLO4545ID55545789Hg545235F45255452Hgf76DJF56HgKJfg3456356356346534534653456sghey45656jhgjfgghdfhgdfhdfhdfhdfhghhq94375dj93458w34')
False
Parameters:value – string to validate SHA512 encoding

ismimetype

validus.ismimetype(value)[source]

Checks if the provided string matches to a correct Media type format (MIME type) If the value is a valid MIME Type, this function returns True, otherwise False.

Examples:

>>> ismimetype('application/xhtml+xml')
True

>>> ismimetype('application/json/text')
False
Parameters:value – string to validate MIME Type

isisrc

validus.isisrc(value)[source]

Checks if the provided string is valid ISRC(International Standard Recording Code) If the value is a valid ISRC, this function returns True, otherwise False.

Examples:

>>> isisrc('USAT29900609')
True

>>> isisrc('USAT2990060')
False
Parameters:value – string to validate MIME Type