Regular Expressions 101

Community Patterns

Community Library Entry

1

Regular Expression
Created·2021-06-27 14:07
Flavor·PCRE2 (PHP)

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

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