How to validate a raw Zebra Programming Language (ZPL) file with a regular expression?

2.5k views Asked by At

When receiving ZPL raw labels (text files) from a third party, I would like to run a regular expression on them to validate them.

Rather than a 100% strict validation, I am mostly looking to avoid sending to the printer obviously wrong files, such as completely unrelated text files, or binary files.

I am not familiar enough with ZPL/ZPL-II and I would prefer to use an existing resource for that. Would you know if one exists?

1

There are 1 answers

1
Ovi Tisler On

I've never heard of one. But it wouldn't be too hard to validate. ZPL is pretty straightforward, especially if there's a very defined set that you send to your printer...

The ZPL command characters are ~ for immediate commands an ^ for formatting commands.

Label formats must begin with a ^XA and end with a ^XZ.

Download commands typically begin with a ~D<something>, like ~DY, ~DG, ~DT, ~DC etc.

There are a couple status commands like ~HI and ~HS

There may be a couple other edge cases, but these are the most common commands.