While i was exploring the Power Apps community i saw an interesting questions posted by a user. It gave me a little idea to write a blog post as well and provide the solution to user as well.
Scenario: You want to create a Password reset application. You have to ensure that the new Password adheres to your global policy for Passwords i.e. it should include some upper case and lower case letters, it should have digit and should have a special characters.
Solution:
There could be different approaches to this solution but i particularly like the IsMatch function of Power Apps and i am going to solve the problem through it.
So to solve the problem, Lets create a canvas app and add an input field and a button

The first thing i need to check is if the Password meets my required length. I will be using the Len function of PowerApps. Simple code. I get the length of my first text field and check if its greater then 4. If its true do nothing if its false i set a variable e with possible error statement.
If(Len(password1.Text)>4,0,Set(e,"Error in length"));
Now the next bits are interesting. I want to check if there is a numeric digit in the password. Now i will use isMatch function
If(IsMatch(password1.Text,"[0-9]" ,Contains),0,Set(e,"must contain a numeric digit"))
To break this down for you, i am using Regular Expression to match and used the Contains parameter here so there if there is even a single match it should return true.
Similarly i have added code for Upper Case, Lower Case and Special Characters
My final code on submit button looks like
Set(e,"");If(password1.Text=password2.Text ,0,Set(e,"Two fields are not same")); If(Len(password1.Text)>4,0,Set(e,"Error in length"));If(IsMatch(password1.Text,"[0-9]" ,Contains),0,Set(e,"must contain a numeric digit"));If(IsMatch(password1.Text, "[a-z]" ,Contains),0,Set(e,"Must contain small case letter"));If(IsMatch(password1.Text,"[A-Z]" ,Contains),0,Set(e,"Must contain one uper case letter"));If(IsMatch(password1.Text,"[$&+?@#^*()%!]" ,Contains),0,Set(e,"no special character"));
The placing of these is important.
- So first i am setting the error value to empty before starting a new check
- Then i check if two fields are the same
- Length of password
- Upper case and lower case letter or numeric digit or special characters
The reason i put checking two text fields first is because if anything else is fasle it will overwrite that error so i need to make sure before user get the error of the same fields i should make sure that the password in first field satisfies my requirment.

Hope this quick tip will help you make better apps 🙂
Comments