@@ -16,7 +16,7 @@ export const IS_PHONE_NUMBER = 'isPhoneNumber';
1616 *
1717 * @param value the potential phone number string to test
1818 * @param region 2 characters uppercase country code (e.g. DE, US, CH) for country specific validation.
19- * @param acceptedNumbersTypes list of accepted number types (MOBILE, PAGER, etc...) if not provided check only MOBILE .
19+ * @param acceptedNumbersTypes list of accepted number types (MOBILE, PAGER, etc...) if not provided then accept all valid numbers .
2020 * If text doesn't start with the international calling code (e.g. +41), then you must set this parameter.
2121 */
2222export function isPhoneNumber (
@@ -26,9 +26,21 @@ export function isPhoneNumber(
2626) : boolean {
2727 try {
2828 // the list of all phone number types that are the output of .getType() method
29- let checkedNumberTypes = [ 'MOBILE' ] ;
29+ let checkedNumberTypes = [
30+ 'FIXED_LINE_OR_MOBILE' ,
31+ 'MOBILE' ,
32+ 'FIXED_LINE' ,
33+ 'PREMIUM_RATE' ,
34+ 'TOLL_FREE' ,
35+ 'SHARED_COST' ,
36+ 'VOIP' ,
37+ 'PERSONAL_NUMBER' ,
38+ 'PAGER' ,
39+ 'UAN' ,
40+ 'VOICEMAIL' ,
41+ ] ;
3042
31- // Checking if accepted types array is passed to override the default MOBILE number type
43+ // Checking if accepted types array is passed to override the default
3244 if ( acceptedNumbersTypes ) {
3345 checkedNumberTypes = acceptedNumbersTypes ;
3446 }
@@ -37,7 +49,7 @@ export function isPhoneNumber(
3749
3850 // number must be valid and is one of the phone types the function accepts (ALL TYPES PROVIDED IN phone-number-types.ts)
3951 const result : boolean = ! ! phoneNum ?. isValid ( ) && ! ! checkedNumberTypes . some ( item => item === phoneNum ?. getType ( ) ) ;
40- return ! ! result ;
52+ return result ;
4153 } catch ( error ) {
4254 // logging?
4355 return false ;
@@ -49,7 +61,7 @@ export function isPhoneNumber(
4961 * the intl. calling code, if the calling code wont be provided then the region must be set.
5062 *
5163 * @param region 2 characters uppercase country code (e.g. DE, US, CH) for country specific validation.
52- * @param acceptedNumbersTypes list of accepted number types (MOBILE, PAGER, etc...) if not provided check only MOBILE.
64+ * @param acceptedNumbersTypes list of accepted number types (MOBILE, PAGER, etc...) if not provided then accept all valid phone numbers
5365 * If text doesn't start with the international calling code (e.g. +41), then you must set this parameter.
5466 */
5567export function IsPhoneNumber ( region ?: CountryCode , validationOptions ?: ValidationOptions ,
0 commit comments