I keep seeing regex on phone numbers that allows the number as all one string, and does not make someone enter the hyphen. Using these:
/^[-\s]$/
/^(-\s)$/
/^[-]$/
/^(-)$/
/^([-]\s)$/
as a regex allows spaces or no hyphen to be typed at all. How do you require a hyphen to be inserted?
EDIT: There shouldn't be downvotes that claim "you shouldn't be forcing someone to use this!". This is the client's requirement, and if you ever had to read phone numbers that were 1234567890 instead of 123-456-7890, that would enable you to see an area code and phone exchange at a glance, I would think anyone would want this.
And not that it should matter to the question in any way because it was kept vague and specific on purpose, but this is for a textbox that will not require any non-NANP numbers. I did that on purpose so we can focus on how to require hyphens, not reinvent the wheel on phone number regexs.