Regular Expressions 101

Community Patterns

Simple TIN number regex

1

Regular Expression
PCRE (PHP <7.3)

/
^(?![-])(?!.*[-]$)(?!.*[-]{2})[0-9-]{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.

Assuming the app validates the length.

Submitted by Sowed Castelli - 3 years ago (Last modified 8 months ago)