Reputation: 38721
How can I validate that a string ends with exactly three digits?
valid:
Hey-12-Therexx-111
001
xxx-5x444
invalid:
Hey-12-Therexx-1111
Hey-12-Therexx-11
Hey-12-Therexx
12
112x
Upvotes: 2
Views: 985
Reputation: 183251
You can write:
/(^|\D)\d{3}$/
which means, "start-of-string-or-non-digit-character, followed by three digits, followed by end-of-string".
Upvotes: 9