<script type="text/javascript" language="javascript"> function keyRestrict(e, validchars, casesensitives, onceevery, onceoneof) { onceevery = onceevery ? onceevery : ""; onceoneof = onceoneof ? onceoneof : ""; if (!validchars) return true; var key='', keychar='', obj='', i = 0; var key = e.which ? e.which : window.event.keyCode; var obj = e.target ? e.target : window.event.srcElement; if (key == null) return true; keychar = String.fromCharCode(key); validchars = (validchars + onceevery + onceoneof); if (!casesensitives) {keychar = keychar.toLowerCase();validchars = validchars.toLowerCase();onceevery = onceevery.toLowerCase(); onceoneof = onceoneof.toLowerCase();} for (i=0; i<(onceevery + onceoneof).length; i++) { if (i < onceevery.length) { if (obj.value.indexOf(onceevery.charAt(i)) != -1 && keychar == onceevery.charAt(i)) return false; } else {if (obj.value.indexOf(onceoneof.charAt(i-onceevery.length)) != -1 && onceoneof.indexOf(keychar) != -1) return false;}} if (validchars.indexOf(keychar) != -1) return true; if ( key==null || key==0 || key==8 || key==9 || key==13 || key==27 ) return true; return false; }</script>
Function Call in on Text Field
<asp:textbox font-size="10px" id="txt_a" maxlength="15" onkeypress="return keyRestrict(event,'abcdefghijklmnopqrstuvwxyz0123456789^')" runat="server" text=""></asp:textbox>
1 comment:
good share
Post a Comment