Skip to main content

Notifications

Power Apps - Building Power Apps
Suggested answer

How do I validate a field to check if a URL starts with a 'https://' or 'http://' ?

Posted on by 759
I have a field set up for a URL. I want to make sure the user enters 'http://' or 'https://' at the beginning of the URL. If not I want an error message to show, I've tried this but for some reason it only work is only 'http://' or 'https://' is entered. Anything after that it fails. What am I missing?
 
If(!IsMatch(TXT_BaseURL.Text,"^https?://.+"),Notify("Invalid URL: URL should start with 'https://' or 'http://'",NotificationType.Error))
 
  • Mark Nanneman Profile Picture
    Mark Nanneman 329 on at
    How do I validate a field to check if a URL starts with a 'https://' or 'http://' ?
    Another option is to preload the field with "https://" in the value property, or you could just auto-fix it for the user whenever the data has to be submitted.  If you were just saving the input to a variable, you could do it like this:

    If(
        !StartsWith(Lower(txt_url.Value),"https://") And !StartsWith(Lower(txt_url.Value),"http://"),
        Set(varUrlInput, $"https://{txt_url.Value}"),
        Set(varUrlInput, txt_url.Value)
    )




  • Suggested answer
    ronaldwalcott Profile Picture
    ronaldwalcott 1,026 on at
    How do I validate a field to check if a URL starts with a 'https://' or 'http://' ?
    Did you try using MatchOptions.BeginsWith
     
    If(!IsMatch(TXT_BaseURL.Text,"^https?://.+",MatchOptions.BeginsWith),Notify("Invalid URL: URL should start with 'https://' or 'http://'",NotificationType.Error))
     
     

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

November 2024 Newsletter…

November 2024 Community Newsletter…

Community Update Oct 28…

Power Platform Community Update…

Tuesday Tip #7 Community Profile Tips…

Welcome to a brand new series, Tuesday Tips…

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 143,487

#2
RandyHayes Profile Picture

RandyHayes 76,308

#3
Pstork1 Profile Picture

Pstork1 64,014

Leaderboard