Skip to content

Commit

Permalink
is_slug_added
Browse files Browse the repository at this point in the history
  • Loading branch information
codeperfectplus committed May 30, 2024
1 parent 01a78b3 commit 8f04432
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 9 deletions.
8 changes: 8 additions & 0 deletions docs/string/string_validation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,11 @@ The following functions are used to validate strings.
>>> val.contains("abc", "d")
False

:code:`isSlug(input_string)`
Returns true if the string contains the substring.

>>> val.contains("foo-bar")
True
>>> val.contains("foo bar)
False

13 changes: 4 additions & 9 deletions sanatio/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ def __isvalidString(self, value: str) -> bool:
if isinstance(value, str):
return True

return False

def __isvalidNumber(self, value: int)-> bool:
""" check if the number is valid or not """
if value is None:
Expand All @@ -30,8 +28,6 @@ def __isvalidNumber(self, value: int)-> bool:
if isinstance(value, (int, float)):
return True

return False

def __isvalidBoolean(self, value: bool)-> bool:
""" check if the string is boolean or not """
if value is None:
Expand All @@ -40,8 +36,6 @@ def __isvalidBoolean(self, value: bool)-> bool:
if isinstance(value, bool):
return True

return False

def isAadharCard(self, value)-> bool:
""" check if the string is Aadhar card or not """
regex = "^[2-9]{1}[0-9]{3}[0-9]{4}[0-9]{4}$" # need to improve regex for space and hyphen
Expand All @@ -55,8 +49,6 @@ def isAadharCard(self, value)-> bool:
if checksum_aadhar(value):
return True

return False

def isPostalCode(self, value, locale: str)-> bool:
""" check if the string is postal code or not """
country_data = all_country[locale]
Expand Down Expand Up @@ -352,7 +344,10 @@ def isPort(self, value: int) -> bool:

def isSlug(self, value: str) -> bool:
""" check if the string is slug or not """
pass
regex = "^[a-z0-9-]+$"
if re.match(regex, value):
return True
return False

def isStrongPassword(self, value: str) -> bool:
""" check if the string is strong password or not
Expand Down
9 changes: 9 additions & 0 deletions tests/string_case_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,15 @@ def test_isEmpty_false(self):
self.assertFalse(validator.isEmpty('foo'))
self.assertFalse(validator.isEmpty(' foo '))

def test_isSlug_true(self):
self.assertTrue(validator.isSlug('foo-bar'))
self.assertTrue(validator.isSlug('foo-bar-123'))
self.assertTrue(validator.isSlug('foo-bar-123-456'))

def test_isSlug_false(self):
self.assertFalse(validator.isSlug('foo bar'))



if __name__ == '__main__':
unittest.main()

0 comments on commit 8f04432

Please sign in to comment.