Hi
I am new to jquery.
I am trying to block special charcters from entering textboxes and textareas across my application. I have written the below mentioned function in a seperate .js file:
$(document).ready(
function
() {
$(
'input[type="text"],textarea'
).bind(
'change'
,
function
() {
// $('textarea[id$=txtfpconfirmcomments]').change(function (event) {
alert(
this
.id);
if
(
this
.value.match(/[^a-zA-Z0-9 ]/g)) {
this
.value =
this
.value.replace(/[^a-zA-Z0-9 ]/g,
''
);
}
});
});
I have added references in master page:
<script src="scripts/jquery-1.8.2.js" type="text/javascript"></script>
<
script
src
="scripts/jquery-1.8.2.min.js"
type
="text/javascript"></
script
>
<
script
language
="javascript"
src
="Scripts/CommentScript.js"
type
="text/javascript"></
script
>
This function works fine(special characters are getting removed) for textbox when the page is loaded,but if i perform any other action on the page and try to enter special character again in the textbox, it doesnot work at all. But if i refresh the page it starts working again.For textarea its not working fine probably because because the text area is getting loaded on click. Kindly help me solve my issue.