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, otherwiseFalse.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, otherwiseFalse.Examples:
>>> isprintascii('1234abcDEF') True >>> isprintascii('foobar') False
Parameters: value – string to validate printable ASCII chars
isnonempty¶
isbase64¶
-
validus.isbase64(value)[source]¶ Return whether or not given value is base64 encoded. If the value is base64 encoded, this function returns
True, otherwiseFalse.Examples:
>>> isbase64('U3VzcGVuZGlzc2UgbGVjdHVzIGxlbw==') True >>> isbase64('Vml2YW11cyBmZXJtZtesting123') False
Parameters: value – string to validate base64 encoding
isemail¶
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, otherwiseFalse.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, otherwiseFalse.Examples:
>>> ishexcolor('#ff0034') True >>> ishexcolor('#ff12FG') False
Parameters: value – string to validate hexadecimal color
isrgbcolor¶
isint¶
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, otherwiseFalse.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, otherwiseFalse.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, otherwiseFalse.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, otherwiseFalse.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, otherwiseFalse.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, otherwiseFalse.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, otherwiseFalse.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, otherwiseFalse.Examples:
>>> ishalfwidth('l-btn_02--active') True >>> ishalfwidth('0011') False
Parameters: value – string to validate half-width chars
islatitude¶
islongitude¶
ismac¶
ismd5¶
-
validus.ismd5(value)[source]¶ Return whether or not given value is MD5 encoded. If the value is MD5 encoded, this function returns
True, otherwiseFalse.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, otherwiseFalse.Examples:
>>> ismongoid('507f1f77bcf86cd799439011') True >>> ismongoid('507f1f77bcf86cd7994390') False
Parameters: value – string to validate MongoDB ObjectId
isiso8601¶
isipv4¶
isipv6¶
isip¶
isport¶
isdns¶
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, otherwiseFalse.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, otherwiseFalse.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, otherwiseFalse.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, otherwiseFalse.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, otherwiseFalse, 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, otherwiseFalse.Examples:
>>> isdatauri('data:text/plain;base64,Vml2YW11cyBmZXJtZW50dW0gc2VtcGVyIHBvcnRhLg==') True >>> isdatauri('dataxbase64data:HelloWorld') False
Parameters: value – string to validate base64 encoded data URI
isjson¶
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, otherwiseFalse.Examples:
>>> istime('30 Nov 00', '%d %b %y') True >>> istime('Friday', '%d') False
Parameters: - value – string to validate time
- fmt – format of time
isurl¶
iscrcard¶
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, otherwiseFalse.Examples:
>>> isisin('AU0000XVGZA3') True >>> isisin('DE000BAY0018') False
Parameters: value – string to validate ISIN
isiban¶
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, otherwiseFalse. Supported locales are:ar-DZ,ar-SY,ar-SA,en-US,en-CA,cs-CZ,de-DE,da-DKel-GR,en-AU,en-GB,en-HK,zh-HK,en-IN,en-NG,en-NZ,en-ZA,en-ZMes-ES,fi-FI,fr-FR,he-IL,hu-HU,id-ID,it-IT,ja-JP,ms-MY,nb-NOnl-BE,fr-BE,nn-NO,pl-PL,pt-BR,pt-PT,ro-RO,en-PK,ru-RU,sr-RStr-TR,vi-VN,zh-CN,zh-TW,bn-BDExamples:
>>> 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, otherwiseFalse.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, otherwiseFalse.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, otherwiseFalse.Examples:
>>> isisbn13('978-4-87311-368-5') True >>> isisbn13('01234567890ab') False
Parameters: isbn – ISBN version 13 string to validate
ispositive¶
isimei¶
issha1¶
-
validus.issha1(value)[source]¶ Return whether or not given value is SHA1 encoded. If the value is SHA1 encoded, this function returns
True, otherwiseFalse.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, otherwiseFalse.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, otherwiseFalse.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, otherwiseFalse.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, otherwiseFalse.Examples:
>>> isisrc('USAT29900609') True >>> isisrc('USAT2990060') False
Parameters: value – string to validate MIME Type