Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you write a regular expression with optional character * at the end of a TIN?

Tags:

c#

regex

The regular expression for a TIN is ^\d{3}-\d{2}-\d{4}$, but I need to accept the following (with or without the "*"):

123-45-6789 or 123-45-6789*

like image 707
Chaka Avatar asked Nov 24 '25 16:11

Chaka


1 Answers

Make it match one * (normally a special character, but escaped with the backslash it becomes the literal * character), optionally (with ?, which means 0 or 1 of the previous):

^\d{3}-\d{2}-\d{4}\*?$
like image 110
Cameron Avatar answered Nov 27 '25 06:11

Cameron



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!