This is a migrated thread and some comments may be shown as answers.

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

4 Answers 150 Views
Input
This is a migrated thread and some comments may be shown as answers.
RichElliott
Top achievements
Rank 1
RichElliott asked on 28 Jul 2008, 02:03 PM
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

4 Answers, 1 is accepted

Sort by
0
Accepted
Missing User
answered on 29 Jul 2008, 09:57 AM
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.
0
RichElliott
Top achievements
Rank 1
answered on 29 Jul 2008, 03:46 PM
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

0
Simon
Top achievements
Rank 1
answered on 16 Aug 2008, 10:03 AM
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
0
plamen
Top achievements
Rank 1
answered on 24 Oct 2008, 12:20 PM
Tags
Input
Asked by
RichElliott
Top achievements
Rank 1
Answers by
Missing User
RichElliott
Top achievements
Rank 1
Simon
Top achievements
Rank 1
plamen
Top achievements
Rank 1
Share this question
or