1

I created a simple javascript function that receives a string and parses through it and updates other form fields. The function is called when I use a scanner to read a 2D barcode. My problem is that there are multiple fields separated with ascii code 29 which is the "group separator". I'm trying convert all the special characters to a readable string like "". I tried doing a replace like:

var BC = barcodestring.replace(String.fromCharCode(29), '');

Also, will the "replace" function replace just 1 or all of the occurrences?

1 Answer 1

1

This should work to replace the default replace function to it replaces all of that character.

barcodestring  = barcodestring.replace(new RegExp(String.fromCharCode(29).replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&'), 'g'), "")
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.