locked
Avoid Junk characters in asp.net textbox RRS feed

  • Question

  • Hi

      I need to avoid entry of junk characters in asp.net text box field.

     Eg : If user enter junk characters say 这是一个传真 i need to prompt a message that "Junk characters are not allowed in text box"

     How to validate and remove?

    Regards,

    Sivakumar

    • Moved by Caillen Thursday, September 4, 2014 6:17 AM
    Wednesday, September 3, 2014 7:50 AM

Answers

  • You can activate a regex validation. Use something like this:

    <asp:RegularExpressionValidator id="RegularExpressionValidator1"
                       ControlToValidate="yourTextBoxID"
                       ValidationExpression="[0-9a-zA-Z]+"
                       Display="Static"
                       EnableClientScript="true"
                       ErrorMessage="some message"
                       runat="server"/>

     

    Noam B.


    Do not Forget to Vote as Answer/Helpful, please. It encourages us to help you...

    • Proposed as answer by Just Karl Friday, September 12, 2014 10:33 PM
    • Marked as answer by Just Karl Tuesday, September 16, 2014 10:39 PM
    Wednesday, September 3, 2014 10:36 AM
  • Please post questions related to ASP.NET in the ASP.NET forums (http://forums.asp.net).
    • Proposed as answer by Caillen Thursday, September 4, 2014 6:17 AM
    • Marked as answer by Just Karl Tuesday, September 16, 2014 10:39 PM
    Wednesday, September 3, 2014 2:07 PM

All replies

  • You can activate a regex validation. Use something like this:

    <asp:RegularExpressionValidator id="RegularExpressionValidator1"
                       ControlToValidate="yourTextBoxID"
                       ValidationExpression="[0-9a-zA-Z]+"
                       Display="Static"
                       EnableClientScript="true"
                       ErrorMessage="some message"
                       runat="server"/>

     

    Noam B.


    Do not Forget to Vote as Answer/Helpful, please. It encourages us to help you...

    • Proposed as answer by Just Karl Friday, September 12, 2014 10:33 PM
    • Marked as answer by Just Karl Tuesday, September 16, 2014 10:39 PM
    Wednesday, September 3, 2014 10:36 AM
  • Please post questions related to ASP.NET in the ASP.NET forums (http://forums.asp.net).
    • Proposed as answer by Caillen Thursday, September 4, 2014 6:17 AM
    • Marked as answer by Just Karl Tuesday, September 16, 2014 10:39 PM
    Wednesday, September 3, 2014 2:07 PM