Blocking HTML Tags OR Allow only one HTML Tag for Text box using java script
Script :-
<script type="text/javascript">
function ScriptTagsValidation(e, objCtrl) {
var key = window.event ? e.keyCode : e.which;
var keychar = String.fromCharCode(key);
var PreviousValue = objCtrl.value;
var containchars;
var count = 0;
if (keychar == "<" || keychar == ">") {
var Tags = "<>";
for (var d = 0; d < PreviousValue.length; d++) {
containchars = PreviousValue.charAt(d);
if (Tags.indexOf(containchars) != -1) {
count++;
}
}
if (count == 1) {
return false;
}
}
return true;
}
</script>
Design :-
<asp:TextBox ID="TextBox1" runat="server" onkeypress="return ScriptTagsValidation(event,this);"></asp:TextBox>
0 comments:
Post a Comment