Regex to allow either dots or dashes and dots
What should be the Regex to allow a string that only contains either dots or dots and hyphens (limited hyphens enforced)?
And disallow when a string contains otherwise
Example: Allowed
- 10.0.0.1
- 10.0.0.1-what-is-this-descriptor
- v10.0.0.1
Disallowed
- abc123
- 10.0.0.1-what-is-this-descriptor-now-what-there-what
- what.there.now.what-there
Below is the regex tried, confirms that below allows either “dots” as well as “dots + dashes” however not able to enforce to 4 hyphens and should always start with dots or dots+dashes:
^[a-z0-9\.\-]{5,}$
Read more here: Source link
