Skip to main content

Validate an email input in a Canvas Application | PowerApps

Validate an email input in a Canvas Application | PowerApps

In this post let us see, how to Validate an email input in a Canvas Application

  • UI Validations helps us to ensure, valid data is received from the End User to complete an operation
  • helps end user to provide right information
the validation action depends on the type of the input control
  1. for Text Input Control - mostly we go with "OnChange"
  2. for check box control - "OnCheck and On uncheck"
  3. for Drop Down and Combo Box Controls - "OnChange" or "OnSelect" etc.,
Now, let us see how can we validate an email input, a phone number input and a name input.

How to validate an email input value is valid?

We can leverage "Regex" (Regular Expressions) to valid user inputs.

Let us consider the Email Input Control Name as - txtEmail.Text.
OnChange of this Control let us implement "IsMatch" function - which returns true or false based on the inputs.

IsMatch(txtEmail.Text,Email) - If the value entered in txtEmail is a valid email address it returns true otherwise false.

How this Email function validates the inputs - this expression checks for ".", "@" - are provided in the email or not and returns the boolean value accordingly.

To let the user know in case of invalid email - let us show an error message on the screen. For that take a label and update it's text to "please enter a valid email" and "OnChange" of the Email Input -If(IsMatch(txtEmail.Text,Email),UpdateContext({locValidEmail:true}),UpdateContext({locValidEmail:false}))
So, if the entered email value is valid the locValidEmail variable returns true otherwise false. So, now go to the error message label added above and update it's visible property value to "locValidEmail"

Email Input
Valid Email Formula
 Email

Now, let us use this IsMatch function to validate an email input with a specific domain email addresses. So, we should let user to enter only emails with @gmail.com.

OnChange of the Email Input field use this - txtEmail.Text,"^([a-zA-Z0-9\_\.]+@gmail.com)" 
This allows user to enter email with "_", "." and only accounts associated with google.

Comments