Regular Expressions 101

Community Patterns

Simple TIN number regex

1

Regular Expression
PCRE2 (PHP >=7.3)

/
^(?![-])(?!.*[-]$)(?!.*[-]{2})[0-9-]+$
/
gm

Description

  • Only accept numerics/digits and hyphens, forbidding them at the start and the end of the number, and avoid two consecutive occurrences.
Submitted by Sowed Castelli - 3 years ago