Skip to content
This repository was archived by the owner on May 17, 2024. It is now read-only.

Commit 916e644

Browse files
committed
add simple email validation
1 parent afff6f1 commit 916e644

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

data_diff/dbt.py

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import os
2+
import re
23
import time
34
import webbrowser
45
from typing import List, Optional, Dict
@@ -399,13 +400,24 @@ def _initialize_events(dbt_user_id: Optional[str], dbt_version: Optional[str], d
399400

400401

401402
def _email_signup() -> None:
403+
email_regex = r'^[\w\.\+-]+@[\w\.-]+\.\w+$'
404+
prompt = "\nWould you like to be notified when a new data-diff version is available?\n\nEnter email or leave blank to opt out (we'll only ask once).\n"
405+
402406
if bool_ask_for_email():
403-
email_input = Prompt.ask(
404-
"\nWould you like to be notified when a new data-diff version is available?\n\nEnter email or leave blank to opt out (we'll only ask once).\n",
405-
default="",
406-
show_default=False,
407-
)
408-
email = email_input.strip()
407+
while True:
408+
email_input = Prompt.ask(
409+
prompt=prompt,
410+
default="",
411+
show_default=False,
412+
)
413+
email = email_input.strip()
414+
415+
if email == "" or re.match(email_regex, email):
416+
break
417+
418+
prompt = ""
419+
rich.print("[red]Invalid email. Please enter a valid email or leave it blank to opt out.[/]")
420+
409421
if email:
410422
event_json = create_email_signup_event_json(email)
411423
run_as_daemon(send_event_json, event_json)

0 commit comments

Comments
 (0)