cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Spawn10
Helper II
Helper II

How do I prevent a user from entering a url or an email in a text box?

I have a textbox that i want to prevent the user from entering either an email address or a url. I want to disable the submit button any time the user enters either an email address or a url. 

How can I get this done in PowerApps?

1 ACCEPTED SOLUTION

Accepted Solutions
v-qiaqi-msft
Community Support
Community Support

Hi @Spawn10,

Based on the issue that you mentioned, do you want to validate the URL and email address?

Could you please share a bit more about the scenario?

I think the regular expression could achieve your needs.

To validate URL, the following Rex could make it work:

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

To validate the email address, you could just refer to the Email parameter as below:

v-qiaqi-msft_0-1617956839968.png

In a word, please set the DisplayMode property of the submit button as below:

If(
    IsMatch(
        TextInput1.Text,
        "(?:http(s)?:\/\/)?[\w.-]+(?:\.[\w\.-]+)+[\w\-\._~:/?#[\]@!\$&'\(\)\*\+,;=.]+$"
    ) || IsMatch(
        TextInput1.Text,
        Match.Email
    ),
    DisplayMode.Disabled,
    Edit
)

Hope it could help you.

Regards,

Qi

Best Regards,
Qi

View solution in original post

2 REPLIES 2
Pstork1
Dual Super User III
Dual Super User III

You can use the IsMatch() function to check if the textbox contains a match for a regular expression that is an email address or a URL.  Us it in the displaymode of the submit button to disable the control.

IsMatch, Match, and MatchAll functions - Power Apps | Microsoft Docs

If(IsMatch( TextInput1.Text, Email, Contains & IgnoreCase ) || IsMatch(TextInput1.Text, "https://", Contains & IgnoreCase) ,DisplayMode.Disabled, DisplayMode.Edit)

 



-------------------------------------------------------------------------
If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.
v-qiaqi-msft
Community Support
Community Support

Hi @Spawn10,

Based on the issue that you mentioned, do you want to validate the URL and email address?

Could you please share a bit more about the scenario?

I think the regular expression could achieve your needs.

To validate URL, the following Rex could make it work:

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

To validate the email address, you could just refer to the Email parameter as below:

v-qiaqi-msft_0-1617956839968.png

In a word, please set the DisplayMode property of the submit button as below:

If(
    IsMatch(
        TextInput1.Text,
        "(?:http(s)?:\/\/)?[\w.-]+(?:\.[\w\.-]+)+[\w\-\._~:/?#[\]@!\$&'\(\)\*\+,;=.]+$"
    ) || IsMatch(
        TextInput1.Text,
        Match.Email
    ),
    DisplayMode.Disabled,
    Edit
)

Hope it could help you.

Regards,

Qi

Best Regards,
Qi

View solution in original post

Helpful resources

Announcements
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

M365 768x460.jpg

Microsoft 365 Collaboration Conference | December 7–9, 2021

Join us, in-person, December 7–9 in Las Vegas, for the largest gathering of the Microsoft community in the world.

Top Solution Authors
Top Kudoed Authors
Users online (2,255)