cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
myatix
Helper I
Helper I

Validation of Input field onSelect

 

 

 

 

 

 

Hi All,

 

I am trying to validate a data entry in an input field (Input1) dynamically based on the users selection of another field (Dropdown1) on the form.

I am not able to create a dynamic Regular Expression as PowerApps doesn't support building Regex expressions on the fly, so I have added a regular expression that covers all scenarios on Input1.

 

What I would like to do is when the user is submits the form (onSelect) check that Input1 contains the correct information. IE: The Country code matches the country selected in the form.

 

(4 Alphabetic Characters) (Country Code) (2 Alphanumeric or 5 Alphanumeric Characters)

 

This is my Regex:

 

 

 

^[A-Z]{4}(AD|AE|AF|AG|AI|AL|AM|AN|AO|AQ|AR|AS|AT|AU|AW|AZ|BA|BB|BD|BE|BF|BG|BH|BI|BJ|BM|BN|BO|BQ|BR|BS|BT|BV|BW|BY|BZ|CA|CC|CD|CF|CG|CH|CI|CK|CL|CM|CN|CO|CR|CS|CU|CV|CW|CX|CY|CZ|DE|DJ|DK|DM|DO|DZ|EC|EE|EG|EH|ER|ES|ET|FI|FJ|FK|FM|FO|FR|GA|GB|GD|GE|GF|GH|GI|GL|GM|GN|GP|GQ|GR|GS|GT|GU|GW|GY|HK|HM|HN|HR|HT|HU|ID|IE|IL|IN|IO|IQ|IR|IS|IT|JM|JO|JP|K1|K5|KE|KG|KH|KI|KM|KN|KP|KR|KW|KY|KZ|LA|LB|LC|LI|LK|LR|LS|LT|LU|LV|LY|MA|MC|MD|ME|MG|MH|MK|ML|MM|MN|MO|MP|MQ|MR|MS|MT|MU|MV|MW|MX|MY|MZ|NA|NC|NE|NF|NG|NI|NL|NO|NP|NR|NU|NZ|OM|PA|PE|PF|PG|PH|PK|PL|PM|PN|PR|PS|PT|PW|PY|QA|RE|RO|RS|RU|RW|SA|SB|SC|SD|SE|SG|SH|SI|SJ|SK|SL|SM|SN|SO|SR|ST|SV|SX|SY|SZ|TC|TD|TF|TG|TH|TJ|TK|TM|TN|TO|TP|TR|TT|TV|TW|TZ|UA|UG|UM|US|UY|UZ|VA|VC|VE|VG|VI|VN|VU|WF|WS|XI|XK|YE|YT|YU|Z1|Z2|Z3|Z4|Z5|Z6|Z7|ZA|ZM|ZW)[A-Z0-9]{2}([A-Z0-9]{3})?$

 

 

 

 

The dynamic part of the check is the country code which needs to be the same as the country code provided when the user selects a country in dropdown1.

 

 

 

 

LookUp(Countries, Title = ddCountry.SelectedText.Result, CountryCode)

 

 

 

 

I hope this makes sense...

 

In the ideal world I would like to do this on the Input1 field for the onChange property... But it doesn't work!

 

 

 

 

If(
!IsMatch(txtSwift.Text, "^[A-Z]{4}(" & LookUp(Countries, Title = ddCountry.SelectedText.Result, CountryCode) & ")[A-Z0-9]{2}([A-Z0-9]{3})?$"),
Notify("The entered data does not match the required format, e.g. ABCDDK1A or ABCDDK1A2B3", NotificationType.Error);Reset(txtSwift)
)

 

 

 

 

I hope someone has a good idea how I resolve this issue?

 

Thanks! 🙂

 

 

 

8 REPLIES 8
LukeShive
Helper I
Helper I

You could just put Regex data into table and use IsBlank to check if user input is in table.

Thanks for the reply! I am not sure I understand your suggestion?

 

I was thinking of doing something like this...

 

Set(
    varCountryCode,
    Mid(
        txtSwift,
        2,
        4
    )
);
If(
    varCountryCode = LookUp(
        Countries,
        Title = ddCountry.SelectedText.Result,
        CountryCode
    ),
    SubmitForm(FrmBankMasterData)
);

 

But this doesn't seem to work either???

If(
   IsBlank(
           LookUp(
                  Countries,
                  CountryCode=txtSwiftText
                  )
           )=true,
           Notify("The entered data does not match the required format, e.g. ABCDDK1A or ABCDDK1A2B3",NotificationType.Error
                  )
)

@LukeShive 

I don't think you have understood what I need to validate... 

 

 

If(
   IsBlank(
           LookUp(
                  Countries,
                  CountryCode=txtSwift.Text
                  )
           )=true,
           Notify("The entered data does not match the required format, e.g. ABCDDK1A or ABCDDK1A2B3",NotificationType.Error
                  )
)

 

 

I do not want to check if countryCode=txtSwift.Text, it is much more complex than that...

 

I want to check if the txtSwift.Txt contains the CountryCode in a specific position within the text string as I explained in the original post.

 

(4 Alphabetic Characters) (2 Character CountryCode) (2 Alphanumeric or 5 Alphanumeric Characters)

 

EG:

If Dropdown1 = United Kingdom

then check the CountryCode is UK in the following position within txtSwift.Text

ABCDUK1D

or

If Dropdown1 = United States

then check the CountryCode is US in the following position within txtSwift.Text

ACDKUS5C22D

 

I would imagine it should be something like this on the OnSelect button?

 

If(
     Mid(
        txtSwift.Text,
        2,
        4
    ) = LookUp(
        Countries,
        Title = ddCountry.SelectedText.Result,
        CountryCode
    ),
    SubmitForm(FrmBankMasterData)
);

 

 

I hope this clarifies any misunderstanding. 🙂

Well in that case something like this should do trick. /I may have messed up comas though 😄

 

If(
	Len(txtSwift.Text)<11,
	Notify("The entered data does not match the required format, e.g. ABCDDK1A or ABCDDK1A2B3",NotificationType.Error),
	Set(
		varChkitout,
		If(
			IsMatch(
				Left(txtSwift.Text,4),
					MultipleLetters & MultipleLetters & MultipleLetters & MultipleLetters
					)=true,
					1,
					0
			)
		)&&
	Set(
		varChkitout,
		If(
			IsBlank(
				LookUp(
					  Countries,
					  CountryCode=Mid(txtSwift.Text,5,2)
					)
				)=false,
			varChkitout,
			varChkitout+1				
			)
		)&&
	Set(
		varChkitout,
		If(
			IsMatch(
				Right(txtSwift.Text,2),
					Digit & Digit
					)=true 
					OR
					Right(txtSwift.Text,5),
					Digit & Digit & Digit & Digit & Digit
			)=true,
			varChkitout,
			varChkitout+1
			)&&
	If(
		varChkitout<>3,
		Notify("The entered data does not match the required format, e.g. ABCDDK1A or ABCDDK1A2B3",NotificationType.Error)
	)
)

 

 

myatix
Helper I
Helper I

We're on the right path... 🙂

 

But it isn't:

 

 

Len(txtSwift.Text)<11,
Notify("The entered data does not match the required format, e.g. ABCDDK1A or ABCDDK1A2B3",NotificationType.Error),

 

 

Because it is ONLY 8 or 11 characters, not less than 11 (IE: 1,2,3,4,5,6,7,9 and 10 characters are NOT valid.)

 

This is perfect for the first 4 characters (All letters)

 

 

IsMatch(
Left(txtSwift.Text,4),
MultipleLetters & MultipleLetters & MultipleLetters & MultipleLetters
)=true,
1,
0
)

 

 

Then we need to check if the selected Country in Dropdown1 matches the CountryCode in txtSwift. (5th and 6th Character only)

 

Dropdown1 Dataset

Title, CountryCode

United Kingdom, UK

United States, US

Denmark, DK

 

Example txtSwift:

ABCDUK1D

(BoldText = CountryCode to match against Dropdown1, CountryCode)

 

 

If(
     Mid(
        txtSwift.Text,
        2,
        4
    ) = LookUp(
        Countries,
        Title = ddCountry.SelectedText.Result,
        CountryCode
    ),
    true
);

 

 

The following doesn't work as the last 2 or 5 characters can be either a digit or a letter.

 

If(
			IsMatch(
				Right(txtSwift.Text,2),
					Digit & Digit
					)=true 
					OR
					Right(txtSwift.Text,5),
					Digit & Digit & Digit & Digit & Digit
			)=true,
			varChkitout,
			varChkitout+1
			)

 

 

 But perhaps you could combine 2 regex IsMatch with Mid Function to validate it...

 

 

For Example:

This is not valid code as it is a little above my No Code Low Code capabilities! 😉

 

 

If(
    !IsMatch(txtSwift.Text, "^[A-Z]{4}"), 
    Notify("The entered data does not match the required format, e.g. ABCDDK1A or ABCDDK1A2B3", NotificationType.Error);Reset(txtSwift)
)
&&


If(
     Mid(
        txtSwift.Text,
        2,
        4
    ) = LookUp(
        Countries,
        Title = ddCountry.SelectedText.Result,
        CountryCode
    ),
    true
)&&

If(
    !IsMatch(txtSwift.Text, "[A-Z0-9]{2}([A-Z0-9]{3})?$"), 
    Notify("The entered data does not match the required format, e.g. ABCDDK1A or ABCDDK1A2B3", NotificationType.Error);Reset(txtSwift)
)

 

 

 How would you structure this???

 

LukeShive
Helper I
Helper I

What I have written in my first response was valid it was more about idea than actual copy and paste code. You have to adjust localization comas yourself. This is tested and working solution. This is not clean or optimized code the same thing can be achieved with much less code using just a IsMatch pattern. 

If(
    Len(txtSwift.Text) = 8 Or Len(txtSwift.Text) = 11;
    Set(
        varContryCode;
        Dropdown1.Selected.CountryCode
    ) && Set(
        varChkitout;
        If(
            IsMatch(
                Left(
                    txtSwift.Text;
                    4
                );
                Letter & Letter & Letter & Letter
            ) = true;
            1;
            0
        )
    ) && Set(
        varChkitout;
        If(
            Mid(
                txtSwift.Text;
                5;
                2
            ) = Dropdown1.Selected.CountryCode;
            varChkitout + 1;
            varChkitout
        )
    ) && Set(
        varChkitout;
        If(
            IsMatch(
                Right(
                    txtSwift.Text;
                    2
                );
                "([A-Za-z]+[0-9]|[0-9]+[A-Za-z])[A-Za-z0-9]*"
            ) = true Or IsMatch(
                Right(
                    txtSwift.Text;
                    5
                );
                "([A-Za-z]+[0-9]|[0-9]+[A-Za-z])[A-Za-z0-9]*"
            ) = true;
            varChkitout;
            varChkitout + 1
        )
    ) && If(
        varChkitout <> 3;
        Notify(
            "The entered data does not match the required format, e.g. ABCDDK1A or ABCDDK1A2B3";
            NotificationType.Error
        )
    );
    Notify(
        "The entered data does not match the required format, e.g. ABCDDK1A or ABCDDK1A2B3";
        NotificationType.Error
    )
)

 

@LukeShive  I appreciate the help and input! I am not a developer and I guess this is just above my capabilities. Despite trying to correct the localisation comas this code isn't working for me. I guess I will just have to find a simpler solution. It would be so much easier if you could build regex statements on the fly.

 

Thanks again! 

Helpful resources

Announcements

Super User of the Month | Drew Poggemann

As part of a new monthly feature in the Community, we are excited to share that Drew Poggemann is our featured Super User for the month of February 2024. If you've been in the Community for a while, we're sure Drew's name is familiar to you, as he is one of our most active contributors--he's been a Super User for five consecutive seasons!   Since authoring his first reply 5 years ago to his 514th solution authored, Drew has helped countless Community members with his insights and expertise. In addition to being a Super User, Drew is also a User Group leader and a Microsoft MVP. His contributions to our Super User sessions and to the new SUIT program are always welcome--as well as his sense of humor and fun-loving way of sharing what he knows with others.   When Drew is not solving problems and authoring solutions, he's busy overseeing the Solution Architecture team at HBS, specializing in application architecture and business solution strategy--something he's been doing for over 30 years. We are grateful for Drew and the amazing way he has used his talent and skills to help so many others in the Community. If you are part of the SUIT program, you got to hear some great tips from Drew at the first SUIT session--and we know he still has much more to share!You can find him in the Community and on LinkedIn. Thank you for all you do, Drew!

Announcing Power Apps Copilot Cookbook Gallery

We are excited to share that the all-new Copilot Cookbook Gallery for Power Apps is now available in the Power Apps Community, full of tips and tricks on how to best use Microsoft Copilot as you develop and create in Power Apps. The new Copilot Cookbook is your go-to resource when you need inspiration--or when you're stuck--and aren't sure how to best partner with Copilot while creating apps.   Whether you're looking for the best prompts or just want to know about responsible AI use, visit Copilot Cookbook for regular updates you can rely on--while also serving up some of your greatest tips and tricks for the Community. Our team will be reviewing posts using the new "Copilot Studio" label to ensure we highlight and amplify the most relevant and recent content, so you're assured of high-quality content every time you visit. If you share a post that gets featured in the curated gallery, you'll get a PM in the Community to let you know!The curated gallery is ready for you to experience now, so visit the new Copilot Cookbook for Power Apps today: Copilot Cookbook - Power Platform Community. We can't wait to see what you "cook" up!      

Celebrating a New Season of Super Users with Charles Lamanna, CVP Microsoft Business Applications

February 8 was the kickoff to the 2024 Season One Super User program for Power Platform Communities, and we are thrilled to welcome back so many returning Super Users--as well as so many brand new Super Users who started their journey last fall. Our Community Super Users are the true heroes, answering questions, providing solutions, filtering spam, and so much more. The impact they make on the Communities each day is significant, and we wanted to do something special to welcome them at our first kickoff meeting of the year.   Charles Lamanna, Microsoft CVP of Business Applications, has stressed frequently how valuable our Community is to the growth and potential of Power Platform, and we are honored to share this message from him to our 2024 Season One Super Users--as well as anyone who might be interested in joining this elite group of Community members.     If you want to know more about Super Users, check out these posts for more information today:    Power Apps: What is A Super User? - Power Platform CommunityPower Automate: What is A Super User? - Power Platform Community Copilot Studio: What is A Super User? - Power Platform Community Power Pages: What is A Super User? - Power Platform Community

February 2024 User Group Update: Welcoming New Groups and Highlighting Upcoming Events

It's a new month and a brand-new year, which means another opportunity to celebrate our amazing User Groups!Each month, we highlight the new User Groups that have joined the community. It's been a busy season for new groups, because we are thrilled to welcome 15 New User Groups! Take a look at the list below, shared by the different community categories. If your group is listed here, give this post a kudo so we can celebrate with you!   We love our User Groups and the difference they make in the lives of our Community! Thank you to all the new User Groups, new User Group leaders--we look forward to hearing about your successes and the impact you will leave!   In addition to our monthly New User Group spotlight, it's a great time to share some of the latest events happening in our User Group community! Take a look at the list below to find one that fits your schedule and need! There's a great combination of in-person and virtual events to choose from. It's a great time of year to connect and engage with User Groups both locally and online. Please Welcome Our NEW User Groups   Power Platform: Heathcare Power Platform User Group Power Platform Connect Hub Power Platform Usergroup Denmark Mexico Norte- Power Platform User Group Pune Power User Group Sudbury Power Platform User GroupMicrosoft User Group GhanaMPPBLR - Microsoft Power Platform Bengaluru User Group Power Apps:   Myrtle Beach Power Platform User GroupAnanseTechWB PowerApps Copilot Studio: Pathfinders Power Platform Community Dynamics365: Cairo, Egypt MSD 365 Business Central/NAV/F&O User GruopMS Dynamics 365 Business Central LatamCincinnati OH D365 F&O User Group February User Group Events February 2024 Cleveland Power Platform User GroupPortallunsj - Februar 2024Indiana D365/AX February User Group MeetingQ1 2024 KC Power Platform and Dynamics 365 CRM Users Group 

Super Users 2024 Season One is Here!

   We are excited to announce the first season of our 2024 Super Users is here! Our kickoff to the new year welcomes many returning Super Users and several new faces, and it's always exciting to see the impact these incredible individuals will have on the Community in 2024! We are so grateful for the daily difference they make in the Community already and know they will keep staying engaged and excited for all that will happen this year.   How to Spot a Super User in the Community:Have you ever written a post or asked for help in the Community and had it answered by a user with the Super User icon next to their name? It means you have found the actual, real-life superheroes of the Power Platform Community! Super Users are our heroes because of the way they consistently make a difference in the Community. Our amazing Super Users help keep the Community a safe place by flagging spam and letting the Community Managers know about issues. They also make the Community a great place to find answers, because they are often the first to offer solutions and get clarity on questions. Finally, Super Users share valuable insights on ways to keep the Community growing, engaging, and looking ahead!We are honored to reveal the new badges for this season of Super Users! Congratulations to all the new and returning Super Users!     To better answer the question "What is a Super User?" please check out this article: Power Apps: What is A Super User? - Power Platform CommunityPower Automate: What is A Super User? - Power Platform Community Copilot Studio: What is A Super User? - Power Platform Community Power Pages: What is A Super User? - Power Platform Community

Did You Attend the Microsoft Power Platform Conference in 2022 or 2023? Claim Your Badge Today!

If you were one of the thousands of people who joined us at the first #MPPC Microsoft Power Platform Conference in 2022 in Orlando--or attended the second-annual conference in Las Vegas in 2023--we are excited to honor you with a special community badge! Show your support for #MPPC Microsoft Power Platform Conference this year by claiming your badge!         Just follow this link to claim your badge for attending #MPPC in 2022 and/or 2023: MPPCBadgeRequest    Want to earn your badge for 2024? Just keep watching our News & Announcements for the latest updates on #MPPC24.

Top Solution Authors
Top Kudoed Authors
Users online (4,389)