Jump to content

Remove Special Characters for Input Fields


Recommended Posts

So, I was testing this new HowTo Article I found.

 

It seems that it will not work for the Inline Insert and Inline Edit, so, I made one, if ever anyone needs it

 

INLINE INSERT

<script type="text/javascript">
document.addEventListener('input', function(event) {
var x = document.getElementById("InlineAddFIELDNAME").value;
document.getElementById("InlineAddFIELDNAME").value=x.replace(/[^a-zA-Z0-9 ]/g, "");
});
</script>

I set the event listener to input as the Inline Insert and Edit is not a form, this will, however, PREVENT special characters for being typed or pasted into the input

 

INLINE EDIT

 
<script type="text/javascript">

document.addEventListener("click", function(event){
if(event.srcElement.getAttribute("data-cb-name") == 'InlineEdit'){

document.addEventListener('input', function(e){

var x = document.querySelector('input[name="InlineEditFIELDNAME"]').value;
document.querySelector('input[name="InlineEditFIELDNAME"]').value=x.replace(/[^a-zA-Z0-9 ]/g, "");

});

}
});

</script> 
 
 
These both works for me, just reply if you encounter any issues.
 
Note: I don't know how to restrict just SOME special characters, but, you can search for any regexes that you can use instead of 'replace(/[^a-zA-Z0-9 ]/g, "")'
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...