Skip to content

Commit

Permalink
idea: implement a phone number validation
Browse files Browse the repository at this point in the history
  • Loading branch information
shivamgutgutia committed Dec 24, 2023
1 parent de292bd commit 24c8ace
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 16 deletions.
34 changes: 18 additions & 16 deletions controllers/vcf.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,22 +32,24 @@ def vcf():

if "First Name" not in headersMap:
return("The file must have atleast the first name field set",400)

if request.form.get("removeWithoutNumber","")=="true" and "Phone Number" in headersMap:
columns = headersMap["Phone Number"].split(",") if headersMap["Phone Number"] else []
if columns:
mask = df[columns].apply(lambda x: all(x == ""), axis=1)
df = df[~mask]

#Less than 10 or not equal to 10 - must check
if request.form.get("removeLessThan10","")=="true" and "Phone Number" in headersMap:
columns = headersMap["Phone Number"].split(",") if headersMap["Phone Number"] else []
for column in columns:
df[column]=df[column].apply(lambda x: x if len(x)>=10 else "")

if request.form.get("removeDuplicate","")=="true" and "Phone Number" in headersMap:
columns = headersMap["Phone Number"].split(",") if headersMap["Phone Number"] else []
df = df.drop_duplicates(subset=columns,keep="first") if columns else df

if "Phone Number" in headersMap:

if request.form.get("removeWithoutNumber","")=="true":
columns = headersMap["Phone Number"].split(",") if headersMap["Phone Number"] else []
if columns:
mask = df[columns].apply(lambda x: all(x == ""), axis=1)
df = df[~mask]

#Less than 10 or not equal to 10 - must check
if request.form.get("removeLessThan10","")=="true":
columns = headersMap["Phone Number"].split(",") if headersMap["Phone Number"] else []
for column in columns:
df[column]=df[column].apply(lambda x: x if len(x)>=10 else "")

if request.form.get("removeDuplicate","")=="true":
columns = headersMap["Phone Number"].split(",") if headersMap["Phone Number"] else []
df = df.drop_duplicates(subset=columns,keep="first") if columns else df

if request.form.get("sample","")=="false":
if request.form.get("splitVCF","")=="false":
Expand Down
8 changes: 8 additions & 0 deletions utils/validateNumbers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# import phonenumbers

# def validatePhoneNumber(number):
# try:
# parsedNumber = phonenumbers.parse(number)
# return phonenumbers.is_valid_number(parsedNumber)
# except phonenumbers.phonenumberutil.NumberParseException as e:
# return False

0 comments on commit 24c8ace

Please sign in to comment.