Regex that does not allow consecutive dots

You can use it like this with additional lookaheads:

^(?!\.)(?!.*\.$)(?!.*\.\.)[a-zA-Z0-9_.]+$
  • (?!\.) – don’t allow . at start
  • (?!.*\.\.) – don’t allow 2 consecutive dots
  • (?!.*\.$) – don’t allow . at end

Leave a Comment