Skip to content

Instantly share code, notes, and snippets.

Last active December 29, 2021 11:19
What would you like to do?
This html page shows an example of using intTelInput JS Lib for validation of phone numbers.
<link rel="stylesheet" type="text/css" href="">
<script type="text/javascript" src=""></script>
document.addEventListener('DOMContentLoaded', ()=>{
var phones=document.querySelectorAll('input[name=phone]');
for (var i = phones.length - 1; i >= 0; i--) {
function processInput(phone){
var iti = window.intlTelInput(phone,{
allowDropdown: false,
initialCountry: 'RU',
nationalMode: true,
autoPlaceholder: 'aggressive',
formatOnDisplay: true,
separateDialCode: false,
utilsScript: ''
phone.addEventListener('input', ()=> {
if (!iti.isValidNumber()) phone.setCustomValidity('!!!');
<input id='phone1' type='tel' name='phone' required autocomplete='tel' />
<button type='submit'>Submit</button>
<input id='phone2' type='tel' name='phone' required autocomplete='tel' />
<button type='submit'>Submit2</button>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment