Regular Expressions 101

Community Patterns

Community Library Entry

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.

The length of the input is limited by the app.

Submitted by Sowed Castelli - 3 years ago