Regular Expressions 101

Community Library Entry

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 a year ago)