cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
ramanan89
Helper III
Helper III

URL Validation

Hi,

I am using this code for validating link in the form

 

    !IsMatch(DataCardValue2.Text, "(?:http(s)?:\/\/)?[\w.-]+(?:\.[\w\.-]+)+[\w\-\._~:/?#[\]@!\$&'\(\)\*\+,;=.]+$")

 

also tried

 

"(([\w]+:)?//)?(([\d\w]|%[a-fA-f\d]{2,2})+(:([\d\w]|%[a-fA-f\d]{2,2})+)?@)?([\d\w][-\d\w]{0,253}[\d\w]\.)+[\w]{2,63}(:[\d]+)?(/([-//+_~.\d\w]|%[a-fA-f\d]{2,2})*)*(\?(&?([-+_~.\d\w]|%[a-fA-f\d]{2,2})=?)*)?(#([-+_~.\d\w]|%[a-fA-f\d]{2,2})*)?"
//)

 

 

But its not validating the SharePoint and Teams link like below,

 

https://name.sharepoint.com/sites/filename/_layouts/15/Doc.aspx?OR=teams&action=edit&sourcedoc={38B53388-9C2E-4D09-964A-813B747F455A}

 

 and

 

https://teams.microsoft.com/l/file/38B54543-9C0E-4D09-964A-813B737F475A?tenantId=258ac4e4-146a-411e-9dc8-79a9e12fd6da&fileType=pptx&objectUrl=https%3A%2F%2Fname.sharepoint.com%2Fsites%2filenamefilenamefilenamefilenamefilenamefilenamefilenamefilename.pptx&baseUrl=https%3A%2F%2Fname.sharepoint.com%2Fsites%2filename-filename&serviceName=teams&threadId=19:5f2346fc521142ccbb22d38d1edeca68@thread.tacv2&groupId=183435fddb-7ef6-7587-a107-6ecbe64353e5

 

 

It says invalid link, anyway to fix this.

Thanks,

 

1 ACCEPTED SOLUTION

Accepted Solutions
v-bofeng-msft
Community Support
Community Support

Hi @ramanan89 :

Please try this code:

 

IsMatch(DataCardValue2.Text, "(?:http(s):\/\/)[\w.-]+(?:\.[\w.-]+)+[\w\-\.,@?^=%&:/~\+#\{\}]*")

 

 Best Regards,

Bof

View solution in original post

4 REPLIES 4
v-bofeng-msft
Community Support
Community Support

Hi @ramanan89 :

Please try this code:

 

IsMatch(DataCardValue2.Text, "(?:http(s):\/\/)[\w.-]+(?:\.[\w.-]+)+[\w\-\.,@?^=%&:/~\+#\{\}]*")

 

 Best Regards,

Bof

This Works... Thank you so much 🙂

I wonder for the Hyperlink in columns list, max character limit is 255 in SharePoint. But for the share link in Teams itself is more than 255 characters.. 😄

This does not work if pasting from a Copy Link dialogue from SharePoint with "x:, w:" and other characters in the link.

mcastine
Helper I
Helper I

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 this 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

Helpful resources

Announcements
Ignite 2022

WHAT’S NEXT AT MICROSOFT IGNITE 2022

Explore the latest innovations, learn from product experts and partners, level up your skillset, and create connections from around the world.

Power Apps Africa Challenge 2022

Power Apps Africa Challenge

Your chance to join an engaging competition of Power Platform enthusiasts.

Super User 2 - 2022 Congratulations

Welcome Super Users

The Super User program for 2022 - Season 2 has kicked off!

September Events 2022

Check out all of these events

Attend in person or online, there are incredible conferences and events happening all throughout the month of September.

Users online (3,058)