/^(?=[^-]*-?[^-]*$)[0-9-]*[0-9]$/
equivalently
/^[0-9-]*[0-9]$/
You can add a length check in the same pass without requiring viewing
/^[0-9-]{2,}[0-9]$/
These are at least 3 characters, the last is a digit, and the rest are numbers and - . See http://www.rubular.com/r/oa9wVxggz0
You can also limit the first character to - . You can also require 3 digits, not counting - as one of the three required characters. Combining them, we get:
/^[0-9]-*[0-9][0-9-]*[0-9]$/
See http://www.rubular.com/r/Qhl843Txib
source share