Skip to content
Advertisement

Javascript Validation for a phone number (Numbers, spaces, dots, hyphens)

So I have this validation for alphanumeric’s (/^[A-Za-z0-9,+-]+$/) however I want a validation for a phone number which only allows Numbers, Spaces, Dots and Hyphens. What code would I use to check for those.

Thanks Ben

Advertisement

Answer

According to my specifications its just Numbers, Spaces, Dots and Hyphens only. Thats any order and any length

That would be:

/^[0-9 .-]+$/
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement