简体   繁体   中英

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

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="&" />

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.

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.

您可以简单地从字符串中删除那些字符,然后再执行数据库操作。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM