diff --git a/rules/tel.js b/rules/tel.js index aa57ea3..d7698e9 100644 --- a/rules/tel.js +++ b/rules/tel.js @@ -5,9 +5,24 @@ export const tel = function ( formDataTree ) { .map( val => val.trim() ).filter( val => '' !== val ); const isTelephoneNumber = text => { + text = text.replace( /[#*].*$/, '' ); // Remove extension text = text.replaceAll( /[()/.*#\s-]+/g, '' ); - return /^[+]?[0-9]+$/.test( text ); + const international = text.startsWith( '+' ) || text.startsWith( '00' ); + + if ( international ) { + text = `+${ text.replace( /^[+0]+/, '' ) }`; + } + + if ( ! /^[+]?[0-9]+$/.test( text ) ) { + return false; + } + + if ( ! ( 6 < text.length && text.length < 16 ) ) { + return false; + } + + return true; }; if ( ! values.every( isTelephoneNumber ) ) {