Home > front end >  Regex (disallow dots between text)
Regex (disallow dots between text)

Time:12-16

How can I disallow dots between text, specifically in this regex

^$|^[a-zA-Z\\u0080-\\uFFFF0-9\s\-#',\.]{0,}$

So dot is allowed, but I only want to allow if one space follows it like Dr. Smith, but not foo.bar

Should match:

lorem ipsum dolor sit amet

lorem dr. ipsum sit amet

Shouldn't match:

lorem dr.ipsum sit amet

CodePudding user response:

You may use this regex to meet your conditions:

^(?=.{1,30}$)[a-zA-Z\u0080-\uFFFF0-9#',-] (?:\.? [a-zA-Z\u0080-\uFFFF0-9#',-] )*$

Check RegEx Demo

This matches 1 of allowed characters inside [...] optionally followed by an optional dot and a single space followed by same set of allowed characters.

(?=.{1,30}$) restricts max allowed length to 30.

  • Related