I need to validate that a given String contains up to 12 digits and exactly one dash.
Initial RegEx: ^[0-9]*-?[0-9]*$
Modified RegEx: ^([0-9]*-?[0-9]*){1,12}$
Example (should be valid): 12356978-9
The problem is that the first RegEx doesn't validate the length, and the second one doesn't work.
Note: Everything must be done in regex, not checking length using string.length()