From 5d979a38db769231f9986285da77020637c1698c Mon Sep 17 00:00:00 2001 From: kaifbilal Date: Sat, 26 Oct 2024 17:14:06 +0530 Subject: [PATCH 1/2] Email Validation on Subscription Button #129 , added regex!! --- app.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/app.py b/app.py index 94faec4..3348c8f 100644 --- a/app.py +++ b/app.py @@ -12,6 +12,7 @@ import streamlit.components.v1 as components import os from dotenv import load_dotenv +import re #AI Integration import anthropic import datetime @@ -817,11 +818,21 @@ def show_about_and_feedback(): # Subscribe for Updates st.subheader("Subscribe for Updates") st.write("Stay updated with our latest features, activities, and wellness tips.") + + # Email Validation Function + def is_valid_email(email): + # Updated pattern requires text before and after @ and . + pattern = r"^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+\.[a-zA-Z]{2,}$" + return re.match(pattern, email) is not None + email = st.text_input("Enter your email address:") if st.button("Subscribe"): if email: st.success("Thank you for subscribing! You'll receive updates and tips directly to your inbox.") - + else: + st.error("Please enter a valid email address with a format like 'example@domain.com'.") + else: + st.warning("Email address cannot be empty.") st.write("---") st.markdown('

© 2024 SereniFi. All rights reserved.

', unsafe_allow_html=True) From 1104a5593053baa335e4e3a358873fbe80119152 Mon Sep 17 00:00:00 2001 From: kaifbilal Date: Sat, 26 Oct 2024 17:28:40 +0530 Subject: [PATCH 2/2] Email Validation on Subscription Button #129 , added regex!! --- app.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/app.py b/app.py index 3348c8f..b198245 100644 --- a/app.py +++ b/app.py @@ -149,6 +149,12 @@ def load_lottie_url(url: str): return response.json() return None +# Email Validation Function +def is_valid_email(email): + # Updated pattern requires text before and after @ and . + pattern = r"^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+\.[a-zA-Z]{2,}$" + return re.match(pattern, email) is not None + # Main function to control page navigation def main(): selected = option_menu( @@ -818,21 +824,15 @@ def show_about_and_feedback(): # Subscribe for Updates st.subheader("Subscribe for Updates") st.write("Stay updated with our latest features, activities, and wellness tips.") - - # Email Validation Function - def is_valid_email(email): - # Updated pattern requires text before and after @ and . - pattern = r"^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+\.[a-zA-Z]{2,}$" - return re.match(pattern, email) is not None - email = st.text_input("Enter your email address:") if st.button("Subscribe"): - if email: + if is_valid_email(email): st.success("Thank you for subscribing! You'll receive updates and tips directly to your inbox.") else: st.error("Please enter a valid email address with a format like 'example@domain.com'.") - else: - st.warning("Email address cannot be empty.") + + + st.write("---") st.markdown('

© 2024 SereniFi. All rights reserved.

', unsafe_allow_html=True)