Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Power Apps - Building Power Apps
Answered

Email validation in text input

(0) ShareShare
ReportReport
Posted on by 90

Hi there!

I am struggling with a basic email validation if statement and was wondering if someone could help. I have a text input in a power app that requires a user to put in an email address. The conditions required for the email address is either that it is matches the same format of a RegEx statement I have or the text box is blank. Below is the statement:

If(!IsMatch(personalEmaiInput.Text, "^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$") || !IsBlank(personalEmaiInput.Text), Set(varValidEmail, true), Set(varValidEmail, false))

This condition would control the Visible property of the error message. I want it to show the error message only if the email is invalid. This condition is on the OnChange property of the text input. When the conditions are met, it's meant to show an error text message and it should disappear when you enter a valid email address. The problem I am having is that it's showing the error message whether or not the email is valid.

The testing for this I have done is the following:
  • many variations of checking if the text input is blank which include
    • checking if personalEmailInput.Text <> Blank()
    • checking if personalEmailInput.Text <> ""
  • Instead of using "||", I tried using only one condition at a time and they work individually as expected
    • the error message disappears when it meets the conditions

 

Any help or guidance would be appreciated! Please let me know if you need anymore information or screenshots etc.

Categories:
  • iAm_ManCat Profile Picture
    18,201 Most Valuable Professional on at
    Re: Email validation in text input

    😂

     

    No worries, glad it was useful!

  • jojos_iq Profile Picture
    90 on at
    Re: Email validation in text input

    Just messing with you, it was actually a good value link - thanks for that, brother!

  • iAm_ManCat Profile Picture
    18,201 Most Valuable Professional on at
    Re: Email validation in text input

    Added that cos the IsMatch being used doesn't actually catch all valid emails 🤷

  • jojos_iq Profile Picture
    90 on at
    Re: Email validation in text input

    Weird plug but aight

  • iAm_ManCat Profile Picture
    18,201 Most Valuable Professional on at
    Re: Email validation in text input

    Hey I know this is already solved, just going to add here that I have a blog post that covers a regex formula that uses the RFC5322 standard to include all possible allowed characters under that convention

     

    Email validation in Power Apps - iAm_ManCat Blog (iammancat.dev)

     

  • P_Anica Profile Picture
    23 on at
    Re: Email validation in text input

    Hi,

    The following regular expression is a better: 

    IsMatch(tbEmail.Text, "^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$")
  • jojos_iq Profile Picture
    90 on at
    Re: Email validation in text input

    Your solution worked @v-xiaochen-msft - cheers mate!

  • swaminawale Profile Picture
    195 on at
    Re: Email validation in text input

    I did a modification in your code:

     

    If(IsMatch(personalEmaiInput.Text, "^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$") && !IsBlank(personalEmaiInput.Text), Set(varValidEmail, true), Set(varValidEmail, false))

     

    This should work now

  • Verified answer
    v-xiaochen-msft Profile Picture
    on at
    Re: Email validation in text input

    Hi @jojos_iq ,

     

    Please try this

    If(IsMatch(personalEmaiInput.Text, "^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$") || IsBlank(personalEmaiInput.Text), Set(varValidEmail, false), Set(varValidEmail, true))

     

    Best Regards,

    Wearsky

  • jojos_iq Profile Picture
    90 on at
    Re: Email validation in text input

    Hi @v-xiaochen-msft 

    This one would set the variable to true if it matches, but the variable is used to determine the Visible property of the error message. I don't want it to appear if it matches. I will adjust my problem now in the main post!

    Thank you!

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

🌸 Community Spring Festival 2025 Challenge 🌸

WIN Power Platform Community Conference 2025 tickets!

Markus Franz – Community Spotlight

We are honored to recognize Markus Franz as our April 2025 Community…

Kudos to the March Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 146,524 Most Valuable Professional

#2
RandyHayes Profile Picture

RandyHayes 76,287 Super User 2024 Season 1

#3
Pstork1 Profile Picture

Pstork1 65,906 Most Valuable Professional

Leaderboard