Validate a URL in PowerApps
Do you have a form where you ask a user to enter a website URL ?
There is no direct way to validate URL in PowerApps today, however, you can use IsMatch function along with Regular Expressions to do this.
Here is the expression you need to validate a URL -
IsMatch(URL_Input.Text, "(?:http(s)?:\/\/)?[\w.-]+(?:\.[\w\.-]+)+[\w\-\._~:/?#[\]@!\$&'\(\)\*\+,;=.]+$")
That’s it, now you can use this to change the border-color of the Text Input box so that the app user knows when he URL entered is incorrect.
Here is an example -
Validate URL in PowerApps
The expression that is used in the border color property -
If(!IsBlank(URL_Input.Text), If(IsMatch(URL_Input.Text, "(?:http(s)?:\/\/)?[\w.-]+(?:\.[\w\.-]+)+[\w\-\._~:/?#[\]@!\$&'\(\)\*\+,;=.]"),Green,Red),RGBA(166, 166, 166, 1))
Hope this helped.
Don’t forget to follow the blog to get the latest content on Power Platform.
Also, you can follow me on Twitter and subscribe to my channel on YouTube .
Comments:
Beat -
This doesn’t work if the URL has /folder/subfolder/etc. This one works (from https://www.regextester.com/94502) (?:http(s)?:\/\/)?[\w.-]+(?:\.[\w\.-]+)+[\w\-\._~:/?#[\]@!\$&’\(\)\*\+,;=.]+$
#### [That API Guy]( "") -
Thank you for pointing that out. I have updated the blog post. :)
#### [Power Apps – Validate the URL only if the URL is entered in text box – Shakir's Blog](http://shakirmajeed.com/2020/03/06/772/ "") -
[…] out the following urlhttps://thatapiguy.tech/2019/09/18/validate-a-url-in-powerapps/, well written quick […]
#### [Fernando]( "[email protected]") -
Thanks, but this not works for url with %20 This one fix this problem: (?:http(s)?:\/\/)?[\w.-]+(?:\.[\w\.-]+)+[\w\-\._~:/?#[\]%@!\$&’\(\)\*\+,;=.]+$
#### [Indhaa]( "[email protected]") -
I amended the expression since it doesn’t validate if URL is with sub folders and %2. The below works for me now “(?:http(s)?:\/\/)?[\w.-]+(?:\.[\w\.-]+)+[\w\-\._~:/?#[\]@!\$&’\(\)\*\+,;=.]+[\%\w]+$”
#### [Marie]( "[email protected]") -
How would I add more items to this code? I would like more items required (like this URL) where they can only put in URLs for a specific site: https://www.sitename.com/ <– this is good http://www.sksjdhfsjdhf.com/ <– this is not good https://www.sitename.com/pagename.html <– this is good https://www.sitename.com/foldername/pagename.html <– this is good