user975447
user975447

Reputation: 11

Match if several identical characters in a string

I would like to match if a string contains more than 1 identical character, for example : Using PHP preg_match or similar function.

the character would be "-"

Something-or other : no match
Test-tes-t : match

Basically what I want to do is disallow the use of more than 1 "-" in a user input.

Upvotes: 1

Views: 146

Answers (1)

duri
duri

Reputation: 15351

Isn't just substr_count($text, '-') > 1 enough?

Upvotes: 6

Related Questions