The following functions are used to validate strings.
from sanatio import Sanatio
val = Sanatio()
isEquals(value1, value2, ignoreCase)
Returns true if the two strings are equal.
>>> val.equals("abc", "abc") True >>> val.equals("abc", "ABC") False >>> val.equals("abc", "ABC", ignoreCase=True) True
isLength(value, min, max)
Returns true if the string is between the specified min and max.
>>> val.isLength("abc", 2, 3) True >>> val.isLength("abc", 2, 2) False
isEmpty(value)
Returns true if the string is empty.
>>> val.isEmpty("") True >>> val.isEmpty("abc") False
isAlphanumeric(value)
Returns true if the string is alphanumeric.
>>> val.isAlphanumeric("abc123") True >>> val.isAlphanumeric("abc123!") False
isAlpha(value)
Returns true if the string is alphabetic.
>>> val.isAlpha("abc") True >>> val.isAlpha("abc123") False
contains(value, substring)
Returns true if the string contains the substring.
>>> val.contains("abc", "a") True >>> val.contains("abc", "d") False
isSlug(input_string)
Returns true if the string contains the substring.
>>> val.contains("foo-bar") True >>> val.contains("foo bar) False
isAlphanumeric(value)
Returns true if the string is an email.
>>> val.isAlphanumeric("abc123") True
isLength(value)
Returns if the string has the valid length.
>>> val.isLength("abc", 2, 3) True >>> val.isLength("abc", 2, 2) False
isEmpty(value)
Returns if the string is empty.
>>> val.isEmpty("") True >>> val.isEmpty("abc") False
isVowel(value)
Returns if the string is a vowel.
>>> val.isVowel("abc") True >>> val.isVowel("bcd") False
isConsonant(value)
Returns if the string is a consonant.
>>> val.isConsonant("abc") True >>> val.isConsonant("aaa") False
trim(value)
Returns the string without leading or trailing spaces.
>>> val.trim(" abc ") "abc"
ltrim(value)
Returns the string without leading spaces.
>>> val.ltrim(" abc ") "abc "
rtrim(value)
Returns the string without trailing spaces.
>>> val.rtrim(" abc ") " abc"
toUpperCase(value)
Returns the string in uppercase.
>>> val.toUpperCase("abc") "ABC"
toLowerCase(value)
Returns the string in lowercase.
>>> val.toLowerCase("ABC") "abc"
removeSpaces(value)
Returns the string without spaces.
>>> val.removeSpaces("a b c") "abc"
removeSymbols(value)
Returns the string without symbols.
>>> val.removeSymbols("a!b@c") "abc"
removeNonASCII(value)
Returns the string without non-ASCII characters.
>>> val.removeNonASCII("a!b@c") "abc"
removeNonWord(value)
Returns the string without non-word characters.
>>> val.removeNonWord("a!b@c") "abc"
removeTags(value)
Returns the string without HTML tags.
>>> val.removeTags("<p>abc</p>") "abc"
removeProtocol(value)
Returns the string without the protocol.
>>> val.removeProtocol("http://www.google.com") "www.google.com"