You should be able to put this into a ".inc" file and then just do
at the top of each page.
If a page doesn't happen to have a
txtName field, I don't think it will hurt. The sub just won't do anything, then.
I hope you are aware that this means that your pages will *ONLY* run with MSIE browsers, as only MSIE allows VBScript in the browser.
If this is the only VBScript you are using in your pages, you'd be much better advised to convert it to JavaScript, so that it would work in all browsers.
Finally, you can simplify the heck out of that code thusly:
Code:
' do this outside the SUB for efficiency:
Dim reZap
reZap = New RegExp
reZap.Pattern = "[\'\/\!\?]"
reZap.Global = True
Sub txtname_onblur()
Dim fld = document.body.all("txtName")
fld.value = reZap.Replace( fld.value, "" )
End Sub
This also makes it easy to add other zappable characters to the list, just by adding them into the .Pattern value.
Alternatively, you could specify only the characters you want to *KEEP* by doing something like:
reZap.Pattern = "[^a-zA-Z0-9\,\s\-]"
which will say "zap all characters *EXCEPT* those I list". (The leading ^ character inverts the sense of the match.)
Lastly, should you decide to change to JavaScript, that's easily done, as well:
<script language=JavaScript>
function txtname_onblur( )
{
var fld = document.forms[0].txtName;
fld.value = fld.value.replace( /[\'\/\!\?]/g, "" );
}
</script>