0

How can I create validation for my phone number field that prevents users just putting multiple zeros instead of an actual phone number?

To make it clear, I just want to prevent the user from entering multiple zeroes to circumvent the other validation in place. I don't really want to follow any sort of pattern as the site I am using it on is international so a variety of different phone numbers will be input...

Takuhii
  • 819
  • 2
  • 8
  • 26
  • possible duplicate of [A comprehensive regex for phone number validation](http://stackoverflow.com/questions/123559/a-comprehensive-regex-for-phone-number-validation) – InbetweenWeekends Sep 30 '15 at 14:14

1 Answers1

1

For the "tel" input the validation is implemented like all other html5 validations by the browser and not all of the handle everything the same (e.g. for the email input the-art-of-web documents it). But you can specify a regex pattern with the pattern attribute to meet your validation needs:

<input type="tel" name="country_code" pattern="[A-Za-z]{3}" />

Browser support is at 84.96% globally. However, especially Android browser lacks it till version 4.4.4. Maybe you want to constitute a javascript based fallback for that if android is crucial (e.g. pure javascript or any available library)

Capricorn
  • 2,061
  • 5
  • 24
  • 31