Add following script to OnLoad event handler:
FilterCharacters = function(fieldname)
{
document.getElementById(fieldname).attachEvent("onkeypress", function()
{
var allowed = "qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM 1234567890,.-";
var pressedkey = String.fromCharCode(event.keyCode);
if (allowed.indexOf(pressedkey) != -1)
return true;
return false;
});
}
if (crmForm.FormType == 1 || crmForm.FormType == 2)
{
//call this method for each field to switch on restriction
FilterCharacters('name');
}
Thanks Andriy. I found your post very useful. I actually implemented this today for one of our fields that is commonly abused with special characters.
ReplyDeleteWhile users were typing in special characters, our main issue with the field was that users would paste in data from another system. Users would often included special unicode characters that actually caused plugins to die-hard (weren't compatible with XML).
The attachevent->onkeypress solution does not catch this. I had to implement a second-check on-change. It would loop through the characters in the field and filter out invalid characters.
Thanks again for the post!