zenstack icon indicating copy to clipboard operation
zenstack copied to clipboard

[Feature Request] Built-in Phone Validation

Open hongkongkiwi opened this issue 1 year ago • 3 comments

Please add an additional validation for phone numbers. This is a pretty common need especially with SMS 2FA, I think this is useful to setup so we can have a @phone

E.164 phone number (used for Phone/SMS etc)

/**
 * Validates a string field value is a valid E.164 phone number format (+[country code][number])
 */
attribute @phone(_ message: String?) @@@targetField([StringField]) @@@validation @@@supportTypeDef

I'm currently using it with a regex, but I think it's worth having it built-in:

  /// The phone number in E.164 format (e.g., +16175551212)
  phone String? @regex('^\\+[1-9]\\d{1,14}$', message: "Phone number must be in E.164 format (e.g., +16175551212)")

hongkongkiwi avatar Nov 30 '24 15:11 hongkongkiwi

Related https://github.com/colinhacks/zod/issues/3378

ymc9 avatar Dec 02 '24 23:12 ymc9

Duplicate of #3378, please close

MickL avatar Dec 04 '24 10:12 MickL

Duplicate of #3378, please close

No this is not a duplicate. That is related and links to zod E.164 phone number validation. Which actually seems to have been already added in Zod: https://github.com/colinhacks/zod/pull/3476 as a merged PR back in May.

This issue is for adding @phone (or similar) in zenstack to use this functionality.

hongkongkiwi avatar Dec 05 '24 05:12 hongkongkiwi