0

I am making a validation for my invoiceId which basically allows all letters and numbers and the dash character (-), and it doesn't allow the word draft in any part of the string, for example:

Valid cases:

  • 123456
  • InvoiceId-1234
  • -1234-Invoice-Id

Invalid cases:

  • draft-234
  • invoicedraft123
  • 12345draft
  • -draft

This is the regex I am using to validate alphanumeric characters and special characters:

[a-zA-Z0-9-]+

I have tried the negative look ahead for here are my attempts:

/^\b(?:(?!(D|d)(R|r)(A|a)(F|f)(T|t))[a-zA-Z0-9-]+$/;

This one just stops the word draft at the beginning

and /^((?!draft).)*([a-zA-Z0-9-])$;

This one allows special characters.

Is it posible to have create a regex with my requirements?

Guillermo Sánchez
  • 143
  • 1
  • 3
  • 15

0 Answers0