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

Celebrating the May Super User of the Month: Laurens Martens

  @LaurensM  is an exceptional contributor to the Power Platform Community. Super Users like Laurens inspire others through their example, encouragement, and active participation. We are excited to celebrated Laurens as our Super User of the Month for May 2024.   Consistent Engagement:  He consistently engages with the community by answering forum questions, sharing insights, and providing solutions. Laurens dedication helps other users find answers and overcome challenges.   Community Expertise: As a Super User, Laurens plays a crucial role in maintaining a knowledge sharing environment. Always ensuring a positive experience for everyone.   Leadership: He shares valuable insights on community growth, engagement, and future trends. Their contributions help shape the Power Platform Community.   Congratulations, Laurens Martens, for your outstanding work! Keep inspiring others and making a difference in the community!   Keep up the fantastic work!        

Check out the Copilot Studio Cookbook today!

We are excited to announce our new Copilot Cookbook Gallery in the Copilot Studio Community. We can't wait for you to share your expertise and your experience!    Join us for an amazing opportunity where you'll be one of the first to contribute to the Copilot Cookbook—your ultimate guide to mastering Microsoft Copilot. Whether you're seeking inspiration or grappling with a challenge while crafting apps, you probably already know that Copilot Cookbook is your reliable assistant, offering a wealth of tips and tricks at your fingertips--and we want you to add your expertise. What can you "cook" up?   Click this link to get started: https://aka.ms/CS_Copilot_Cookbook_Gallery   Don't miss out on this exclusive opportunity to be one of the first in the Community to share your app creation journey with Copilot. We'll be announcing a Cookbook Challenge very soon and want to make sure you one of the first "cooks" in the kitchen.   Don't miss your moment--start submitting in the Copilot Cookbook Gallery today!     Thank you,  Engagement Team

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. Check Out the new Copilot Cookbook for Power Apps today: Copilot Cookbook - Power Platform Community.  We can't wait to see what you "cook" up!      

Tuesday Tip | How to Report Spam in Our Community

It's time for another TUESDAY TIPS, your weekly connection with the most insightful tips and tricks that empower both newcomers and veterans in the Power Platform Community! Every Tuesday, we bring you a curated selection of the finest advice, distilled from the resources and tools in the Community. Whether you’re a seasoned member or just getting started, Tuesday Tips are the perfect compass guiding you across the dynamic landscape of the Power Platform Community.   As our community family expands each week, we revisit our essential tools, tips, and tricks to ensure you’re well-versed in the community’s pulse. Keep an eye on the News & Announcements for your weekly Tuesday Tips—you never know what you may learn!   Today's Tip: How to Report Spam in Our Community We strive to maintain a professional and helpful community, and part of that effort involves keeping our platform free of spam. If you encounter a post that you believe is spam, please follow these steps to report it: Locate the Post: Find the post in question within the community.Kebab Menu: Click on the "Kebab" menu | 3 Dots, on the top right of the post.Report Inappropriate Content: Select "Report Inappropriate Content" from the menu.Submit Report: Fill out any necessary details on the form and submit your report.   Our community team will review the report and take appropriate action to ensure our community remains a valuable resource for everyone.   Thank you for helping us keep the community clean and useful!

Community Roundup: A Look Back at Our Last 10 Tuesday Tips

As we continue to grow and learn together, it's important to reflect on the valuable insights we've shared. For today's #TuesdayTip, we're excited to take a moment to look back at the last 10 tips we've shared in case you missed any or want to revisit them. Thanks for your incredible support for this series--we're so glad it was able to help so many of you navigate your community experience!   Getting Started in the Community An overview of everything you need to know about navigating the community on one page!  Community Links: ○ Power Apps ○ Power Automate  ○ Power Pages  ○ Copilot Studio    Community Ranks and YOU Have you ever wondered how your fellow community members ascend the ranks within our community? We explain everything about ranks and how to achieve points so you can climb up in the rankings! Community Links: ○ Power Apps ○ Power Automate  ○ Power Pages  ○ Copilot Studio    Powering Up Your Community Profile Your Community User Profile is how the Community knows you--so it's essential that it works the way you need it to! From changing your username to updating contact information, this Knowledge Base Article is your best resource for powering up your profile. Community Links: ○ Power Apps ○ Power Automate  ○ Power Pages  ○ Copilot Studio    Community Blogs--A Great Place to Start There's so much you'll discover in the Community Blogs, and we hope you'll check them out today!  Community Links: ○ Power Apps ○ Power Automate  ○ Power Pages  ○ Copilot Studio    Unlocking Community Achievements and Earning Badges Across the Communities, you'll see badges on users profile that recognize and reward their engagement and contributions. Check out some details on Community badges--and find out more in the detailed link at the end of the article! Community Links: ○ Power Apps  ○ Power Automate  ○ Power Pages  ○ Copilot Studio    Blogging in the Community Interested in blogging? Everything you need to know on writing blogs in our four communities! Get started blogging across the Power Platform communities today! Community Links: ○ Power Apps  ○ Power Automate  ○ Power Pages  ○ Copilot Studio   Subscriptions & Notifications We don't want you to miss a thing in the community! Read all about how to subscribe to sections of our forums and how to setup your notifications! Community Links: ○ Power Apps  ○ Power Automate  ○ Power Pages  ○ Copilot Studio   Getting Started with Private Messages & Macros Do you want to enhance your communication in the Community and streamline your interactions? One of the best ways to do this is to ensure you are using Private Messaging--and the ever-handy macros that are available to you as a Community member! Community Links: ○ Power Apps  ○ Power Automate  ○ Power Pages  ○ Copilot Studio   Community User Groups Learn everything about being part of, starting, or leading a User Group in the Power Platform Community. Community Links: ○ Power Apps  ○ Power Automate  ○ Power Pages  ○ Copilot Studio   Update Your Community Profile Today! Keep your community profile up to date which is essential for staying connected and engaged with the community. Community Links: ○ Power Apps  ○ Power Automate  ○ Power Pages  ○ Copilot Studio   Thank you for being an integral part of our journey.   Here's to many more Tuesday Tips as we pave the way for a brighter, more connected future! As always, watch the News & Announcements for the next set of tips, coming soon!

Hear what's next for the Power Up Program

Hear from Principal Program Manager, Dimpi Gandhi, to discover the latest enhancements to the Microsoft #PowerUpProgram, including a new accelerated video-based curriculum crafted with the expertise of Microsoft MVPs, Rory Neary and Charlie Phipps-Bennett. If you’d like to hear what’s coming next, click the link below to sign up today! https://aka.ms/PowerUp  

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