Skip to main content

Notifications

Power Apps - Building Power Apps
Answered

Restrict text field only to alphabets and spaces

(0) ShareShare
ReportReport
Posted on by 1,085

I have a text field "City Name" on my Power Apps Canvas App. How can I restrict the text field only to Alphabet and Spaces. It shouldn't allow any special characters or numbers. 

Categories:
  • Sri Profile Picture
    Sri 559 on at
    Re: Restrict text field only to alphabets and spaces

    Hi,

    In my case I have a number field which allows + and - symbol to enter in the field and gives a error message " The value - cannot be converted to a number". For other special characters it's not allowing to enter. 

     

    Any help would be greatly appreciated.

  • Verified answer
    Re: Restrict text field only to alphabets and spaces

    Hi @RameshMukka ,

    Do you want to restrict a textinput that user could only enter Alphabet and Spaces?

    I'm afraid it's not supported to directly restrict a textinput to not allow characters or numbers. 

    For a textinput, you could only restrict whether you enter number or text. Text includes Alphabet, Spaces and character.

    727.PNG

     

    As an alternative solution, I suggest you add a justification when updating.

    If the data in textinput includes characters or numbers, you could not update data and get a warning.

    If the data in textinput only includes Alphabet and Spaces, you could update successfully.

    You just need to set the submit button's OnSelect like this:

    If(IsMatch(TextInput1.Text, "[a-zA-Z\s]+"),
    //[a-zA-Z\s] represents Alphabet and Spaces, + represnets one or more
     SubmitForm(formname),
     Notify("please do not enter character or number in this field!",NotificationType.Warning)
    )
     

     

    Best regards,

     

  • Verified answer
    mdevaney Profile Picture
    mdevaney 29,987 on at
    Re: Restrict text field only to alphabets and spaces

    @RameshMukka 
    This is not possible in a Power Apps text field.  You can restrict input to numbers only but not letters.

    As a workaround you can check whether only letters and spaces were input into the text box using this code

     

    IsMatch(TextInput1.Text, "[a-zA-Z\s]+")

     

    More details on the ISMATCH function here:

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

     

    ---
    Please click "Accept as Solution" if my post answered your question so that others may find it more quickly. If you found this post helpful consider giving it a "Thumbs Up." 

  • Verified answer
    Pstork1 Profile Picture
    Pstork1 64,996 on at
    Re: Restrict text field only to alphabets and spaces

    There is no easy way to limit the characters that a user enters into a text field.  However, you could easily setup a label with an error message and have that message display if the user types a non-allowed character by testing the input with an IsMatch() regex expression.

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

Microsoft Kickstarter Events…

Register for Microsoft Kickstarter Events…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Announcing Forum Attachment Improvements!

We're excited to announce that attachments for replies in forums and improved…

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 145,666

#2
RandyHayes Profile Picture

RandyHayes 76,287

#3
Pstork1 Profile Picture

Pstork1 64,996

Leaderboard