Skip to content

Commit

Permalink
Create string_utils.py
Browse files Browse the repository at this point in the history
  • Loading branch information
KOSASIH authored Aug 14, 2024
1 parent a7d1814 commit de518f5
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions projects/PiNetAI/utils/string_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# string_utils.py

import re

def validate_email(email):
pattern = r"^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$"
return re.match(pattern, email) is not None

def validate_password(password):
pattern = r"^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*#?&])[A-Za-z\d@$!%*#?&]{8,}$"
return re.match(pattern, password) is not None

def truncate_string(string, length):
return string[:length] + "..." if len(string) > length else string

0 comments on commit de518f5

Please sign in to comment.