Boy
Boy

Reputation: 435

Regex to allow only numbers, dashes and dots

What should be the Regex to allow a string that contains only numbers (0-9) or dashes (-) or dots (.)?

And disallow when a string contains otherwise (like alphabets or other special characters not listed above).

Example: Allowed

Disallowed

Upvotes: 6

Views: 18015

Answers (1)

katleta3000
katleta3000

Reputation: 2494

Something like this:

^[0-9.-]*$

Upvotes: 13

Related Questions