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



<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, "");

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



<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, "");



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

  • 1 year later...

Just to add to this, if you want your input fields to NOT accept special character inputs right from the get-go (because what the article does is it accepts the special characters and get rids of them once the user hits submit), you can use the following script:


Paste the following on the Footer of the Configure Fields screen:

document.addEventListener('DataPageReady', function (event) {
$('#InsertRecordFIELDNAME').on('keypress', function (e) {
var ingnore_key_codes = [34, 39];
if ($.inArray(e.which, ingnore_key_codes) >= 0) {


Where ingnore_key_codes contain the key codes of the characters you want to be prevented from being typed in. In the above example, 34 and 39 refers to single quote and double quote, respectively.

Make sure to also replace FIELDNAME in InsertRecordFIELDNAME with the name of the field you want to apply the script to.


You may refer to this link for a list of the codes for the characters. Simply add them to the ingnore_key_codes array


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.

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.


  • Create New...