Creating a phone number schema with specific formatting and length constraints can be a bit trick...
phone number schema
i tried this
but Schema.length is not allowed
then i tried this
which won't really work
but also gives me
seems weird this doesn't work?
i tried this
const PhoneNumberSchema = Schema.compose(
Schema.TemplateLiteral(
Schema.String.pipe(Schema.length(3)),
'-',
Schema.String.pipe(Schema.length(3)),
'-',
Schema.String.pipe(Schema.length(4))
),
Schema.Trim.pipe(Schema.length(12))
).pipe(Schema.brand('phoneNumber'));const PhoneNumberSchema = Schema.compose(
Schema.TemplateLiteral(
Schema.String.pipe(Schema.length(3)),
'-',
Schema.String.pipe(Schema.length(3)),
'-',
Schema.String.pipe(Schema.length(4))
),
Schema.Trim.pipe(Schema.length(12))
).pipe(Schema.brand('phoneNumber'));but Schema.length is not allowed
then i tried this
export const PhoneNumberSchema = Schema.compose(
Schema.TemplateLiteral(Schema.String, '-', Schema.String, '-', Schema.String),
Schema.Trim.pipe(Schema.length(12))
).pipe(Schema.brand('phoneNumber'))export const PhoneNumberSchema = Schema.compose(
Schema.TemplateLiteral(Schema.String, '-', Schema.String, '-', Schema.String),
Schema.Trim.pipe(Schema.length(12))
).pipe(Schema.brand('phoneNumber'))which won't really work
but also gives me
export const validateSignUpForm = (formValues: {
firstName: string
lastName: string
phoneNumber: typeof PhoneNumberSchema.Type
validatedCorporationNumber: typeof ValidatedCorporationNumber.Type
}) => {
return Schema.decodeEither(SignUpFormSchema)(formValues).pipe( // <--- type string & Brand<"phonenumber"> is not assignable to type `${string}-${string}-${string}`
Either.match({
onLeft: () => 'invalid form',
onRight: () => 'the form is valid'
})
)
}export const validateSignUpForm = (formValues: {
firstName: string
lastName: string
phoneNumber: typeof PhoneNumberSchema.Type
validatedCorporationNumber: typeof ValidatedCorporationNumber.Type
}) => {
return Schema.decodeEither(SignUpFormSchema)(formValues).pipe( // <--- type string & Brand<"phonenumber"> is not assignable to type `${string}-${string}-${string}`
Either.match({
onLeft: () => 'invalid form',
onRight: () => 'the form is valid'
})
)
}seems weird this doesn't work?
