levipadre
levipadre

Reputation: 619

Regex (disallow dots between text)

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

Upvotes: 1

Views: 92

Answers (1)

anubhava
anubhava

Reputation: 786111

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.

Upvotes: 3

Related Questions