How to validate special character entry in any controls within a page?
I have designed a page where user can write messages and send within a group but i want that if they enter any special character like <>?#@ etc a msg should be displayed irrespective of the crashing of the page.
C开发者_如何学JAVAan anyone help me out???
for that you have to use javaScript validation or any server site validation for javaScript function validate(inputText) { if(inputText.match(/[<>]/)) return false; } function TextBoxValidate() { var txt1=document.getElementById(TextBoxId).value; if(!(validate(inputText))) { alert("incorrect text") return false; } else return true; }
call these function in that text box where you want to validate by using onClientClick="return TextBoxValidate();"
You have 2 possibilities for doing that.
A) You are adding a regularexpression validator to each control B) You use a customvalidator which you can bind to each control too
First solution is the better one for you.
How you do it? See here: http://www.codeproject.com/KB/validation/aspnetvalidation.aspx
It's not reccommended but you can use ValidateRequest="false" in the page declaration to allow values like that to be sucessfully posted back.
e.g. <%@ Page Title="" Language="C#" ValidateRequest="false"..
精彩评论