whatsupprogrammers
whatsupprogrammers

Reputation: 85

disable characters from being entered in textbox

I am building a form and i want to prevent certain characters from being typed in a textbox? I want to disable the " and ' characters in some of my textboxes

Upvotes: 0

Views: 4894

Answers (4)

Jack
Jack

Reputation: 8941

You can simply remove those characters from the string before you perform your database operation.

Upvotes: 1

atrljoe
atrljoe

Reputation: 8151

Using an AJAX ASP FilterTextBox Control would be the way I'd go.

<ajaxToolkit:FilteredTextBoxExtender ID="ftbe" runat="server"
    TargetControlID="TARGETCONTROLIDHERE"         
    FilterType="Custom, Numbers, LowerCaseLetters, UpperCaseLetters, Symbols"
    InvalidChars="&" />

Upvotes: 1

Town
Town

Reputation: 14906

You can use a RegularExpressionValidator along with a regex such as [^"'] to allow all characters except " and '.

(please note, that regex is untested at the moment...)

ASP.NET Validators have both client and server APIs for validation.

Upvotes: 1

cdeszaq
cdeszaq

Reputation: 31300

The safest way is to check the form values on the server-side to see if the input is valid (doesn't include quote characters in your case) and respond with an error if it is invalid.

On the client side, I've had good luck using jQuery Validation.

Remember that arbitrary form payloads can be constructed outside of a browser, so you always have to check data validity on the server, even if client-side validation is in place.

Upvotes: 1

Related Questions