Sep 30, 2013 Ok, so I just spent another $50.00 to update my Express invoice (due to the inability of the older version to display 2 different taxes), and now this new version insists upon entering an Item Code!!! This is ridiculous; many people, like me, do not and cannot have item codes. Step by step guide on how to create a manual invoice. Link to Video: Manually Creating Invoices Creating an invoice manually is the alternate choice to using a LEDES file created by automated billing software. In most cases, your client will require a line item for every function being billed.
I'm quite new to regular expressions and I'm trying to create a regex for the validation of an invoice format.
The pattern should be:JjYy (all 4 characters are legit), used 0, 2 or 4 timese.g. no Y's at all is valid, YY is valid, YYYY is valid, but YYY should fail.Followed by a series of 0's repeating 3 to 10 times.The whole should never exceed 10 characters.
examples:JyjY000000 is valid (albeit quite strange)YY000 is valid000000 is validjjj000 is invalidjjjj0 is invalid
I learned some basics from here, but my regex fails when it shouldn't. Can someone assist in improving it?
My regex so far is: [JjYy]{0}|[JjYy]{2}|[JjYy]{4}[0]{3,10}
.
The following failed also: [JjYy]{0|2|4}[0]{3,10}
5 Answers
As you need the total length to never exceed 10 characters I think you have to handle the three kinds of prefixes separately:
How about:
To check the length is ten characters or less, use a string length function rather than a regular expression - don't hammer nails with a screwdriver, and so forth.
Test:
Produces
If the total length limit is inclusive of the jJyY
part, you can check it with a negative look ahead to make sure there are no more than 10 characters in the string to begin with (?![jJyY0]{11,})
It may depend on what you are using to implement the regular expression. For example I found out the other day that Notepad++ only supports a few basic operators. Things like the pipe are not part of the core regex standard.
I'd suggest something like this:
If you're using a programming language, you'll need to use a string length function to validate the length.
EDIT: actually, you should be able to validate the length by separating the different situations:
You want to limit the string to 10 characters. So in order to do this you have to consider what valid combinations will make up 10 characters.
Valid combinations therefore would be:
- 0000000000
- 000
- cc00000000
- cc000
- cccc000000
- cccc000
So, an expression to include all of these would be: /0{3,10}|[JY]{2}0{3,8}|[JY]{4}0{3,6}/i
A case insensitive match would suffice, although you do get additional performance from some regular expression engines by explicitly saying /[JjYy]/
instead of /[JY]/i
.