Skip to content

Commit dc810eb

Browse files
committed
feat(develop): added option to decorator
1 parent 1903581 commit dc810eb

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/decorator/string/IsPhoneNumber.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,18 @@ export function isPhoneNumber(
4949
* the intl. calling code, if the calling code wont be provided then the region must be set.
5050
*
5151
* @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.
5253
* If text doesn't start with the international calling code (e.g. +41), then you must set this parameter.
5354
*/
54-
export function IsPhoneNumber(region?: CountryCode, validationOptions?: ValidationOptions): PropertyDecorator {
55+
export function IsPhoneNumber(region?: CountryCode, validationOptions?: ValidationOptions,
56+
acceptedNumbersTypes?: Array<PhoneNumberType>
57+
): PropertyDecorator {
5558
return ValidateBy(
5659
{
5760
name: IS_PHONE_NUMBER,
5861
constraints: [region],
5962
validator: {
60-
validate: (value, args): boolean => isPhoneNumber(value, args?.constraints[0]),
63+
validate: (value, args): boolean => isPhoneNumber(value, args?.constraints[0], acceptedNumbersTypes),
6164
defaultMessage: buildMessage(
6265
eachPrefix => eachPrefix + '$property must be a valid phone number',
6366
validationOptions

0 commit comments

Comments
 (0)