@@ -5,12 +5,14 @@ import { parsePhoneNumberFromString, CountryCode } from 'libphonenumber-js';
55export const IS_PHONE_NUMBER = 'isPhoneNumber' ;
66
77/**
8- * Checks if the string is a valid phone number.
8+ * Checks if the string is a valid phone number. To successfully validate any phone number the text must include
9+ * the intl. calling code, if the calling code wont be provided then the region must be set.
10+ *
911 * @param value the potential phone number string to test
10- * @param { string } region 2 characters uppercase country code (e.g. DE, US, CH).
11- * If users must enter the intl. prefix (e.g. +41), then you may pass "ZZ" or null as region .
12+ * @param region 2 characters uppercase country code (e.g. DE, US, CH) for country specific validation .
13+ * If text doesn't start with the international calling code (e.g. +41), then you must set this parameter .
1214 */
13- export function isPhoneNumber ( value : string , region : CountryCode | undefined ) : boolean {
15+ export function isPhoneNumber ( value : string , region ? : CountryCode ) : boolean {
1416 try {
1517 const phoneNum = parsePhoneNumberFromString ( value , region ) ;
1618 const result = phoneNum ?. isValid ( ) ;
@@ -22,14 +24,13 @@ export function isPhoneNumber(value: string, region: CountryCode | undefined): b
2224}
2325
2426/**
25- * Checks if the string is a valid phone number.
26- * @param region 2 characters uppercase country code (e.g. DE, US, CH).
27- * If users must enter the intl. prefix (e.g. +41), then you may pass "ZZ" or null as region.
27+ * Checks if the string is a valid phone number. To successfully validate any phone number the text must include
28+ * the intl. calling code, if the calling code wont be provided then the region must be set.
29+ *
30+ * @param region 2 characters uppercase country code (e.g. DE, US, CH) for country specific validation.
31+ * If text doesn't start with the international calling code (e.g. +41), then you must set this parameter.
2832 */
29- export function IsPhoneNumber (
30- region : CountryCode | undefined ,
31- validationOptions ?: ValidationOptions
32- ) : PropertyDecorator {
33+ export function IsPhoneNumber ( region ?: CountryCode , validationOptions ?: ValidationOptions ) : PropertyDecorator {
3334 return ValidateBy (
3435 {
3536 name : IS_PHONE_NUMBER ,
0 commit comments