开发者

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


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 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.


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


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜