Skip to main content

Notifications

Power Apps - Building Power Apps
Suggested answer

How do I validate accept certain URLs being entered into a form.

(1) ShareShare
ReportReport
Posted on by 279
I have a DataCard with a text field on my Power Apps form, which users utilize to enter in URLs. I want to be able to check the URLs they input at real time. Certain URLs should not be entered. Right now on the Visible property of the ErrorMessage label for the DataCard, I have the following to ensure that they are entering in a valid URL format and not just any text...
 
If(
	IsBlank(URLColumnValue.Text), 
	false, 
	If(
		!IsMatch(
			URLColumnValue.Text,
			"(?:http(s)?:\/\/)?[\w.-]+(?:\.[\w\.-]+)+[\w\-\._~:/?#[\]@!\$&'\(\)\*\+,;=.]+$"
		), 
		true
	)
)


 
This part is working just fine. I also have a button on the form that allows the users to submit data, and in the DisplayMode of the button, I have the following...
 
If(
	!IsMatch(
		URLColumnValue.Text, 
		"(?:http(s)?:\/\/)?[\w.-]+(?:\.[\w\.-]+)+[\w\-\._~:/?#[\]@!\$&'\(\)\*\+,;=.]+$"
	), 
	DisplayMode.Edit, 
	DisplayMode.Disabled
)

 
This works in ensuring that the users enter in a valid URL format. However there are some URLs that are no longer allowed and I want to be able to check that they are not entering those URLs that are not accepted anymore.  
 
Below are example URLs that should be accepted...
 
https://myDomain/site/ABCsite
https://myDomain/site/ABCsite1
https://myDomain/site/ABCsite2

 
 
While anything like these, should not be allowed. 
 
https://myDomain/teams/ABCsite
https://myDomain/teams/ABCsite1
https://myDomain/teams/ABCsite2
https://myDomain/site/XYZsite
https://myDomain/site/XYZsite1
https://myDomain/site/XYZsite2

What would be the best way to implement such a logic, so that I can keep the current functionality while users are not able to submit anything in the format for the banned URLs?
Categories:
  • Suggested answer
    ANB Profile Picture
    ANB 7,060 on at
    How do I validate accept certain URLs being entered into a form.
     
    You can try below code, if you are sure that the URL should not have exact keywords like in above example you mentions: teams and XYZ.
     
    Then you can try below code:
    If(
    	!IsMatch(
    		URLColumnValue.Text, 
    		"(?:http(s)?:\/\/)?[\w.-]+(?:\.[\w\.-]+)+[\w\-\._~:/?#[\]@!\$&'\(\)\*\+,;=.]+$"
    	) And (!("teams" in URLColumnValue.Text) Or !("XYZ" in URLColumnValue.Text)), 
    	DisplayMode.Edit, 
    	DisplayMode.Disabled
    )
     

    Please click Does this answer your question if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it a Like.


    Thanks,
    ANB

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Microsoft Kickstarter Events…

Register for Microsoft Kickstarter Events…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Announcing Forum Attachment Improvements!

We're excited to announce that attachments for replies in forums and improved…

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 145,422

#2
RandyHayes Profile Picture

RandyHayes 76,287

#3
Pstork1 Profile Picture

Pstork1 64,711

Leaderboard