Suzaku
Suzaku

Reputation: 21

A regex that doesn't accept 2 dot and 2 comma consecutively - Allows letters only

What should I add to my regex?

^[a-zA-Z]+$

Upvotes: 0

Views: 219

Answers (1)

Tim Biegeleisen
Tim Biegeleisen

Reputation: 522741

I would phrase your regex as:

^(?!.*[.,]{2})[A-Za-zñÑ.,]+$

Explanation:

  • ^ from the start of the string
  • (?!.*[.,]{2}) assert that no consecutive dots or commas occur
  • [A-Za-zñÑ.,]+ match a letter, including ñ and Ñ, dot or comma, one or more times
  • $ end of the string

Upvotes: 1

Related Questions