I'm looking for regular expression which will match barcode. The barcodes can be 12 or 14 digits long (never 13) and the first digit has to be 8
. Examples:
800909887898
80903243234323
I've got something like this: ^[8]{1}[0-9]{11}$
but I don't know hot to recognize last 2 digits. It's can be 2 digits character or null (the expression [0-9]{0-2}
will not work fine because quantifier don't work like OR).
To match any number from 0 to 9 we use \d in regex. It will match any single digit number from 0 to 9. \d means [0-9] or match any number from 0 to 9. Instead of writing 0123456789 the shorthand version is [0-9] where [] is used for character range.
Regular Expressions (Regex) are used for barcode data manipulation. With Regex, complicated string matching and character replacement on barcode data is enabled. The Matches condition tries to compare a Regex with the incoming barcode data. The rule execution only continues if the Regex matches the text.
To check for all numbers in a field To get a string contains only numbers (0-9) we use a regular expression (/^[0-9]+$/) which allows only numbers. Next, the match() method of the string object is used to match the said regular expression against the input value.
A regular expression (sometimes called a rational expression) is a sequence of characters that define a search pattern, mainly for use in pattern matching with strings, or string matching, i.e. “find and replace”-like operations.
Check this one
^8[0-9]{11}([0-9]{2})?$
[0-9]{2} means two digits
(...)? means zero or one time
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With