Is is possible to deny certain characters in ASP.NET for AJAX Input controls?

5 posts, 1 answers
  1. RichElliott
    RichElliott avatar
    5 posts
    Member since:
    Jul 2007

    Posted 28 Jul 2008 Link to this post

    Hi all,

    I'm using ASPNET AJAX Q1 2008 in a C# Web Application. I need an input box where the user can type a file name that does not contain any of the characters that Microsoft Windows does not allow in a file name, specifically:
    \ / : * ? " < > |

    I still want to allow upper and lower case letters, numbers, and dashes. Can anyone tell me the best way to do this with RadMaskedTextBox or RadTextBox?

    Thanks a bunch,

    Rich Elliott
    Tigard, Oregon
  2. Answer
    Plamen Peshev
    Admin
    Plamen Peshev avatar
    886 posts

    Posted 29 Jul 2008 Link to this post

    Hi RichElliott,


    You can use the ASP.NET validation controls that are provided with ASP.NET. These controls enable you to check the user's input based on a pattern defined by a regular expression. Take a look at Validating ASP.NET Server Controls for a complete explanation of validation controls and how to use them in your ASP.NET pages.

    Here is an example:

                <asp:RegularExpressionValidator   
                     id="RegularExpressionValidator1"   
                     runat="server"   
                     ErrorMessage="Only gif or jpeg files are allowed!"   
                     ControlToValidate="RadTextBox1"   
                     ValidationExpression="((\w+)\$?)+(.gif|.GIF|.jpeg|.JPEG)$">  
                </asp:RegularExpressionValidator>  
     


    Do not hesitate to write us if you have any other questions.

    All the best,
    Plamen
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. RichElliott
    RichElliott avatar
    5 posts
    Member since:
    Jul 2007

    Posted 29 Jul 2008 Link to this post

    Plamen,

    Thanks!  I am now using the following code which allows upper and lower case letters, numbers, dashes, spaces, and a couple other specific special characters.

    <asp:RegularExpressionValidator ID="validatorTimesheetNotes"

    runat="server"

    ControlToValidate="radtxtbox_TimesheetNotes"

    ValidationExpression="^[a-zA-Z0-9'.;\s-]{1,499}$"

    ErrorMessage="Special characters are not allowed.<br>Must be less than 500 characters."

    Font-Size="Small">

    </asp:RegularExpressionValidator>



    Thanks again,

    Rich Elliott

  5. Simon
    Simon avatar
    32 posts
    Member since:
    Apr 2007

    Posted 16 Aug 2008 Link to this post

    Hello Rich

    Also look at the KeyPress section of the help file.
    They detail how to limit character based on their
    keycode value. This may be simpler than RegEx
    by just using a javascript event to limit characters
    based on their ASCII values.

    Regards,
    Simon
  6. John
    John avatar
    416 posts
    Member since:
    Oct 2006
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017