'Regex to accept only 5 numbers and then a dash or a letter on typescript

I am dealing with an issue with Regex. I have a input which has maxLength 10.

I achieved till now to have the first given value can be digits for example 12345 but then it waits for a dash and after it you can write a letter or again a number maxLength=10 for example: 12345-a121 is allowed and it works with the currrent

But I want to be possible after the 5 digits to be allowed letters or dash because for the moment with this regex it is allowed only dash after 5 digits. For example 12345a or 12345- to be allowed. This is the actual regex what I am using.

Valid/Matches: 12345a235, 123a, 12345-aa1, 12345a, 12345-a.  

Not Valid/Does not matches: -11, 111111, aaaa, 

(?=^[^W_]{1,5}-[^W_]{1,8}$)^.{1,10}$|^[^W_]{1,5}$

I am debugging on the regex101.com but I am not finding a way for that to allow. 12345a for example

This is the condition to check if it matches or not.

if (!this.value.toString().match('^\d{1,5}(?!\d+)[-\p{L}\d]+$') && this.value.toString()) {
      return ValidationInfo.errorCode("You need to do something");

Thank you for the help



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source