Form Validation in Power Apps — Part 1
In this blog, we are going to see how we can do the implementation of form validation in Power Apps.
Let get started, I have designed the Sign-Up page which has the following fields:
- Password and Confirm Password
- Phone Number
Following is Screenshot of my Sign-Up Page build in PowerApps:
![](https://miro.medium.com/max/1365/1*JJvlzP-HlaYeON8y3RZ77w.png)
Following is App Controls Structure which I have followed to Create Sign Up Form:
![](https://miro.medium.com/max/1365/1*0iVW8j540jKAq23DXZK8cA.png)
I have used “ErrorText” which is HTML Label Control for Logging all the Validation Errors.
![](https://miro.medium.com/max/1365/1*6Ag9mcbYogtHmiHJK7I5ag.png)
Now, we will set the Properties on ErrorText control to display the error on the Form for Each Input
Following is an explanation of each validation which I have used in this Power Apps:
Email Validation
- Not(IsBlank(‘ControlName’)) — It will validate if Field is blank or not.
- IsMatch(‘ControlName’.Text , Match.Email) — It will validate the email format and return false if user enter invalid Email Address
- Code:
If(Not(IsBlank('Email Address')),
If(
IsMatch(
'Email Address'.Text,
Match.Email
),
"",
"Please Enter Valid Email <br>"
),
"Please Enter Email <br>"
)
Password and Confirm Password Validation
- Not(IsBlank(‘ControlName’)) — It will validate if Field is blank or not.
- ‘Confirm Password’.Text = Password.Text — It will validate if the password and confirm password are the same or not. It will return false if both password will not match.
- Code:
If(
Not(IsBlank('Confirm Password')) && Not(IsBlank('Password')),
If(
'Confirm Password'.Text = Password.Text,
"",
"Please enter Same Password <br>"
),
"Please Enter Passwords <br>"
)
Phone Number Validation
- Not(IsBlank(‘ControlName’)) — It will validate if Field is blank or not.
- IsMatch(‘Control’.Text, “Your country Phone Validation ReGex”) — It will validate if the entered phone number is valid or not using ReGex.
- I have used phone number validation ReGex for India — “^[6–9]\d{9}$”
- Following is an explanation of my ReGex:
^ #Match the beginning of the string
[6-9] #Match a 6, 7, 8 or 9
\d #Match a digit (0-9 and anything else that is a "digit" in the regex engine)
{9} #Repeat the previous "\d" 9 times (9 digits)
$ #Match the end of the string
5. Code:
If(
Not(IsBlank('Phone Number')),
If(
IsMatch('Phone Number'.Text, "^[6-9]\d{9}$"),
"",
"Please enter Valid Phone No <br>"
),
"Please Enter Phone No. <br>"
)
Following is full code for Validation you need to paste in Formula bar of HtmlText Property:
If(Not(IsBlank('Email Address')),
If(
IsMatch(
'Email Address'.Text,
Match.Email
),
"",
"Please Enter Valid Email <br>"
),
"Please Enter Email <br>"
)&
If(
Not(IsBlank('Confirm Password')) && Not(IsBlank('Password')),
If(
'Confirm Password'.Text = Password.Text,
"",
"Please enter Same Password <br>"
),
"Please Enter Passwords <br>"
)&
If(
Not(IsBlank('Phone Number')),
If(
IsMatch('Phone Number'.Text, "^[6-9]\d{9}$"),
"",
"Please enter Valid Phone No <br>"
),
"Please Enter Phone No. <br>"
)
Result:
Blank Field Validation for each Fields — Email, Password, Confirm Password and Phone Number
![](https://miro.medium.com/max/1365/1*cgenATV6S-7pwI7m_zy11g.png)
Email Format Validation
![](https://miro.medium.com/max/1365/1*DgABrkTIWoRzqqxP70vgFg.png)
Now, you can see after entering valid email error has gone
![](https://miro.medium.com/max/1365/1*hUVc1Iwqdk7elU4dkDe0Yg.png)
Password and Confirm Password Match Validation
![](https://miro.medium.com/max/1365/1*VYVDkhU9YR1Gx-wHkQLQiQ.png)
Phone Number Format Validation Check
![](https://miro.medium.com/max/1318/1*hVCC0C8areDASu9mpQjIgg.png)
After adding valid phone number error is gone
![](https://miro.medium.com/max/1365/1*tyg4PHOmwFNTh8qJeiPujw.png)
Hope this helps, stay tuned for more blogs.