Jignesh Siddhpura
Jignesh Siddhpura

Reputation: 45

regex email validation Ruby

This is my regex for email validation, but I want to restrict consecutive period like I don't want . _ - to be consecutively repeated. Anyone can help me?

/^((?:[a-z]+[0-9_\.-]*)+[a-z0-9_\.-]*[a-z0-9])@((?:[a-z0-9]+[\.-]*)+\.[a-z]{2,4})$/

for example: [email protected] instead i want [email protected] or [email protected] [email protected]

Upvotes: 0

Views: 106

Answers (1)

Ruturaj Bisure
Ruturaj Bisure

Reputation: 159

You can use following regex to avoid consecutive period.

^(?!.*\.{2})\A\S+@.+\.\S+\z

Check it here

You can add,

^(?!.*\.{2}) 

before any email regex that will work to avoid consecutive dots.

Upvotes: 1

Related Questions