Skip to content

Commit 8f04432

Browse files
is_slug_added
1 parent 01a78b3 commit 8f04432

File tree

3 files changed

+21
-9
lines changed

3 files changed

+21
-9
lines changed

docs/string/string_validation.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,11 @@ The following functions are used to validate strings.
5959
>>> val.contains("abc", "d")
6060
False
6161

62+
:code:`isSlug(input_string)`
63+
Returns true if the string contains the substring.
64+
65+
>>> val.contains("foo-bar")
66+
True
67+
>>> val.contains("foo bar)
68+
False
69+

sanatio/main.py

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ def __isvalidString(self, value: str) -> bool:
2020
if isinstance(value, str):
2121
return True
2222

23-
return False
24-
2523
def __isvalidNumber(self, value: int)-> bool:
2624
""" check if the number is valid or not """
2725
if value is None:
@@ -30,8 +28,6 @@ def __isvalidNumber(self, value: int)-> bool:
3028
if isinstance(value, (int, float)):
3129
return True
3230

33-
return False
34-
3531
def __isvalidBoolean(self, value: bool)-> bool:
3632
""" check if the string is boolean or not """
3733
if value is None:
@@ -40,8 +36,6 @@ def __isvalidBoolean(self, value: bool)-> bool:
4036
if isinstance(value, bool):
4137
return True
4238

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

58-
return False
59-
6052
def isPostalCode(self, value, locale: str)-> bool:
6153
""" check if the string is postal code or not """
6254
country_data = all_country[locale]
@@ -352,7 +344,10 @@ def isPort(self, value: int) -> bool:
352344

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

357352
def isStrongPassword(self, value: str) -> bool:
358353
""" check if the string is strong password or not

tests/string_case_test.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,15 @@ def test_isEmpty_false(self):
5858
self.assertFalse(validator.isEmpty('foo'))
5959
self.assertFalse(validator.isEmpty(' foo '))
6060

61+
def test_isSlug_true(self):
62+
self.assertTrue(validator.isSlug('foo-bar'))
63+
self.assertTrue(validator.isSlug('foo-bar-123'))
64+
self.assertTrue(validator.isSlug('foo-bar-123-456'))
65+
66+
def test_isSlug_false(self):
67+
self.assertFalse(validator.isSlug('foo bar'))
68+
69+
6170

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

0 commit comments

Comments
 (0)