0

The short version: I work in a hospital and am attempting to create a safer, more efficient downtime version of the forms we send with blood components for transfusion. Currently we handwrite or type the donor identification number (DIN) and the product code of the unit onto this form, but ideally these are scanned, as they are ISBT 128 barcodes on the unit.

Scanning a DIN gives me ~=W11512003927826 - I would like to have the first two characters (non-alphanumeric) removed, and if possible, the last two. I've been able to accomplish the second task by simply limiting the character input of the field, which is standard and should work fine.

This also applies to the product code, which scans as ~=<E0785V00 and does not need the first three characters.

I've tried a few methods including some Javascript that was supposed to limit the field to only alphanumeric characters, which I assume is probably the simplest way to handle all of this, but either the code was not in the correct syntax for Adobe or I implemented it incorrectly. I am not familiar with JS at all and am just learning form creation.

If anyone has any advice I'd appreciate any help at all. Thanks in advance!

Edit: So far I've tried these three. I'm using these as an action (run a javascript) on mouse exit and also tried on blur.

const alphanumeric = /[a-zA-Z0-9]/g;
const string = "abc-ABC-012";
const result = string.match(alphanumeric).join("");

console.log(result); // abcABC012



const nonalphanumeric = /[_\W]/g;
const string = "abc-ABC-012";
const result = string.replace(nonalphanumeric, "");

console.log(result); // abcABC012




const string = "aa-aa";
const result = string.slice(2, -2);

console.log(string); // aa-aa
console.log(result); // -

1 Answers1

0

I recommend you setup "On Blur" event handlers for each field that needs to accept scanned in data. For the DIN field, adjust the value using:

var field = this.getField("DINField");
field.value = field.value.replace(/^~=(.+)..$/, '$1');

The code above assumes the field is named DINField. Change as appropriate. It is important to use logic like a RegExp for modifying the value because the on-blur event can fire multiple times per field. The code above will only remove the ~= app-id and last two characters once.

Likewise, for the product-id, set on "On Blur" handler to:

var field = this.getField("ProductField");
field.value = field.value.replace(/^~=<(.+)$/, '$1');

The code above assumes the field is named ProductField. This reg-ex only removes the app-id (and not the last two characters).

Mark Warren
  • 1,321
  • 1
  • 7
  • 4