cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
AkshayManke
Continued Contributor
Continued Contributor

Validation for Special Characters

Hello,

 

I am working on an PowerApp where there are few fields in which i want a validation that, if a person enters special characters then the form should not get submitted and to show a warning message. For warning message i can use notify function but how to check and act if a field value consisting of special characters? 

 

Regards,

Akshay

2 ACCEPTED SOLUTIONS

Accepted Solutions

There's a regex for that. Here is an example of doing a up to 9 digit string with no special characters.

 

IsMatch( "AStrongPasswordNot", "(?!^[0-9]\*$)(?!^[a-zA-Z]\*$)([a-zA-Z0-9]{8,10})" )

 

https://docs.microsoft.com/en-us/powerapps/maker/canvas-apps/functions/function-ismatch

 

@AkshayManke if this answers your question, please mark it a solution. 

View solution in original post

v-qiaqi-msft
Community Support
Community Support

Hi@AkshayManke,

Based on the issue that you mentioned, do you want to disable the submit button if there is any special characters in the TextInput?

As @jlindstrom said, IsMatch() can achieve your needs, I have a test on my side, please take a try as below.

Set the OnChange property of the corresponding DataCardValue to TextInput control as below.

IsMatch(DataCardValue6.Text,".*[\\\"&Char(34)&"].*")

To warn the user the invalid characters, add a Label and set the following Text, Visible property as below

Text property: "Special characters are not allowed!"
Visible property: IsMatch(DataCardValue6.Text,".*[\\\"&Char(34)&"].*")

 Set the DisplayMode property of the submit button as below

If(
    !Label5.Visible,
    Edit,
    Disabled
)

Note: Special character in my test are "\" and double quote, you can replace it with yours.

You can check the GIF for reference.

0723Gif2.gif

Best Regards,

Qi

 

Best Regards,
Qi

View solution in original post

9 REPLIES 9

There's a regex for that. Here is an example of doing a up to 9 digit string with no special characters.

 

IsMatch( "AStrongPasswordNot", "(?!^[0-9]\*$)(?!^[a-zA-Z]\*$)([a-zA-Z0-9]{8,10})" )

 

https://docs.microsoft.com/en-us/powerapps/maker/canvas-apps/functions/function-ismatch

 

@AkshayManke if this answers your question, please mark it a solution. 

View solution in original post

v-qiaqi-msft
Community Support
Community Support

Hi@AkshayManke,

Based on the issue that you mentioned, do you want to disable the submit button if there is any special characters in the TextInput?

As @jlindstrom said, IsMatch() can achieve your needs, I have a test on my side, please take a try as below.

Set the OnChange property of the corresponding DataCardValue to TextInput control as below.

IsMatch(DataCardValue6.Text,".*[\\\"&Char(34)&"].*")

To warn the user the invalid characters, add a Label and set the following Text, Visible property as below

Text property: "Special characters are not allowed!"
Visible property: IsMatch(DataCardValue6.Text,".*[\\\"&Char(34)&"].*")

 Set the DisplayMode property of the submit button as below

If(
    !Label5.Visible,
    Edit,
    Disabled
)

Note: Special character in my test are "\" and double quote, you can replace it with yours.

You can check the GIF for reference.

0723Gif2.gif

Best Regards,

Qi

 

Best Regards,
Qi

View solution in original post

AkshayManke
Continued Contributor
Continued Contributor

Hi @jlindstrom@v-qiaqi-msft,

 

The solution given by both of you worked. I have implemented it in my App.

 

Many thanks to both of you..!!

 

Accepting both's solutions!

 

Regards,

Akshay

Thank you this was very help full !!

one question how do i disable the button if i have 2 Labels , if either one of them are showing invalid character message. i tried this below it only blocks the button if both Lables are showing. 

 

 

If(
!Label4 && !Label6.Visible,
Edit,
Disabled 

 

Thank you 

AkshayManke
Continued Contributor
Continued Contributor

Hi @GixStar ,

 

You can try replacing '&&' with 'Or' and see if that works.

 

&& will check if both the conditions are true whereas Or will check of any of the condition is true.

 

Share the result.

 

Kind Regards, 

Akshay

@v-qiaqi-msft 

How can i modify your formula to allow for 4 characters? I need to allow Char(38), Char(45), Char(46) and Char(95) in my text box.

Hi 

i tried that but its still only disabling the Submit button if Label4 and Label6 has invalid characters, if one of them have invalid Characters Submit button is still active.

Thank you 

 

If(
!Label4.Visible Or !Label6.Visible,
Edit,
Disabled

)

AkshayManke
Continued Contributor
Continued Contributor

Hi @GixStar ,

 

I think you can just add parenthesis in the two conditions like below.

If(
!(Label4.Visible) Or !(Label6.Visible),
Edit,
Disabled

)

 

I have created a test on my env. you can refer the below GIF for the same.

 

Condition.gif

Works really well for me. 

With this onchange-code i can block the special characters Char(34) and Char(47).

 

Now my new problem is, as soon as someone set a new line in de multiline datacardvalue-field by clicking the enter-button, the code is like not activ anymore. 

 

does anybody knows how the ismatch is working when enter-button for a new line is clicked in an multiline datacardvalue-field?

 

Thanks

Helpful resources

Announcements
2022 Release Wave 1 760x460.png

2022 Release Wave 1 Plan

Power Platform release plan for the 2022 release wave 1 describes all new features releasing from April 2022 through September 2022.

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

Top Solution Authors
Top Kudoed Authors
Users online (3,160)