Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Power Apps - Building Power Apps
Answered

How do I make a text input throw and error if the format is not correct?

(0) ShareShare
ReportReport
Posted on by 825 Super User 2025 Season 1
I have a text input where the user needs to enter a URL. I want to do very basic checking to make sure they have included a "https://" or "http://" at the beginning. I can get there using this code however it resets the field and means the need to re-type or re-copy and paste the URL back into the field. I would prefer for them to just edit what they put in the field. How can I make this happen?
 
If(
    !StartsWith(TXT_BaseURL.Text, "https://") || !StartsWith(TXT_BaseURL.Text, "http://"),
    Reset(Self);
    Notify("Invalid URL: ULR must start with https:// or http://")
)
Categories:
  • futr_vision Profile Picture
    825 Super User 2025 Season 1 on at
    How do I make a text input throw and error if the format is not correct?
    Nevermind. I can leave the datacard set to true for Required and it works fine. I am guessing but is pushing and error notification signaling that the form is not valid ?
  • futr_vision Profile Picture
    825 Super User 2025 Season 1 on at
    How do I make a text input throw and error if the format is not correct?
    This largely works. I had to make changes to several areas in the app because the field is not set to invalid. For example, the Submit button is looking in Disabled mode until the form is valid. All that matters in this case is that the field in question has some type of input in it. I had to update the Required field of the data card that held the text input field to also check to see if there was an 'https://' or 'http://' before allowing the data card to be set to required. This is the code I used.
     
    If(
        !IsMatch(TXT_BaseURL.Text,"^(https?://)"), true , false
     )
     
    This works but it is incorrect. The field should always be required which this code does not say. Is there a better way to do this?
     
  • Verified answer
    Pstork1 Profile Picture
    65,999 Most Valuable Professional on at
    How do I make a text input throw and error if the format is not correct?
    Instead of using a StartsWith I would use an IsMatch with an REGEX expression in the OnChange action of the text input control.
     
    Here's an article on how to use REGEX to raise an error in a Card in a Form control that uses a text input. Power Apps Text Input Pattern Validation - @WonderLaura

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

🌸 Community Spring Festival 2025 Challenge 🌸

WIN Power Platform Community Conference 2025 tickets!

Markus Franz – Community Spotlight

We are honored to recognize Markus Franz as our April 2025 Community…

Kudos to the March Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 146,660 Most Valuable Professional

#2
RandyHayes Profile Picture

RandyHayes 76,287 Super User 2024 Season 1

#3
Pstork1 Profile Picture

Pstork1 65,999 Most Valuable Professional

Leaderboard