Restricting characters in a text box

If you do not want your end users to input certain characters into a text box, you can use JavaScript to do that. This walkthrough demonstrate how to make a text box not accept characters: #@+!\[].

The files used in this walkthrough can be downloaded here: DiscardChar.doc and DiscardChar.pdf.

  1. Launch Microsoft Word. Choose CenoPDF > Add Text Box to add a text box. In the Text Box Properties dialog box, choose Advanced tab.
  2. Click the Keystroke trigger. Copy and paste the script below into the Execute the JavaScript box.

    for(;;)
    {
        var v = event.change.replace(/[#@+!\\\[\]]/, "");
        if(v == event.change)
            break;
        event.change = v;
    }

    Note: the first parameter in the above replace() function is a regular expression enclosed by two slashes. The script will replace the text that matches the regular expression in a keystroke input (this may include copy and paste action) with an empty string, and keep looping until nothing is replaced.

  3. Click the OK button and choose command CenoPDF > Export to PDF.