8 Replies Latest reply on Apr 6, 2017 5:06 AM by Johan Hedman

# Barcode field and validating data of difference lengths

I’m trying to setup a simple barcode validator that verifies the correct barcode is being used. The validation file always contains numbers that are (5) digits in length.

When I scan the barcodes some maybe 12 digits in length and some maybe 14 digits in length. For example

025880001007

10025880001004

I’m trying to find an easy way to only parse the 5 digits after “25880” "regardless" of the length of data before or after. The Data “25880” isn’t always in the same location. Any Ideas?

Thanks!

• ###### 1. Re: Barcode field and validating data of difference lengths

Use the position() and right() functions together to get the substring

• ###### 2. Re: Barcode field and validating data of difference lengths

Right( YourField ; 5 ) will give you the last 5 digits

• ###### 3. Re: Barcode field and validating data of difference lengths

What if theirs 6 digits after 25880 and I only want 5 digits?

Example:

25880"123456"

I want:

25880"12345" only

• ###### 4. Re: Barcode field and validating data of difference lengths

Let(

pos = Position ( YourField ; "25880" ; 1 ; 1 )

;

middle ( YourField ; pos + 5 ; 5 )

)

This will make your barcode start from 25880 + 5, meaning after 25880 and then take 5 numbers

1 of 1 people found this helpful
• ###### 5. Re: Barcode field and validating data of difference lengths

This is untested, but something like this:

left( right( Position ( barcode ; "25880" ; 1 ; 1 ) + 5 , length(barcode )-5   ), 5)

The +5 -5 may be wrong...

what you want is the end position of 25880, so get the position of 25880 + 5

Then you only want the right of it, so get the length of the barcode and subtract the left half (position of 25880 + 5)

Then because you only want the first 5 digits of that result get the left( ,5)

#Note Johan's answer above is a bit neater!

1 of 1 people found this helpful
• ###### 6. Re: Barcode field and validating data of difference lengths

Thanks Johan and Carl.. Worked great.. Really appreciate the help..

• ###### 7. Re: Barcode field and validating data of difference lengths

One more question for you that I just realized as I don't have a lot of experience with the Let command. Your example worked great but once in awhile I'll get a stray barcode that instead of "25880" it will be "25881". Is their an easy way in that Let statement if it doesn't find "25880" but does find "25881" it would base the results on that number/position instead?

Either way really appreciate your guy's help..

• ###### 8. Re: Barcode field and validating data of difference lengths

Let(

pos =

Case(

Patterncount ( YourField ; "25580" ) = 1 ; Position ( YourField ; "25880" ; 1 ; 1 );

Patterncount ( YourField ; "25581" ) = 1 ; Position ( YourField ; "25881" ; 1 ; 1 )

)

;

middle ( YourField ; pos + 5 ; 5 )

)

1 of 1 people found this helpful