Skip to content

Commit

Permalink
fix: update schema to updated Yup requirements (#662)
Browse files Browse the repository at this point in the history
  • Loading branch information
AndyEPhipps authored Jul 23, 2024
1 parent 2dd8eb7 commit 76b2fdb
Showing 1 changed file with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,30 +68,30 @@ const buildValidationSchema = overrideOptions => {
.when('mp_permissionEmail', {
is: val => (!(mpValidationOptions.mp_permissionEmail.disableOption)
&& mpValidationOptions.mp_permissionEmail[val]),
then: yup.string().required('Please enter your email address').email('Please enter a valid email address')
then: schema => schema.required('Please enter your email address').email('Please enter a valid email address')
}),

mp_mobile: yup.string()
.when('mp_permissionSMS', {
is: val => (!(mpValidationOptions.mp_permissionSMS.disableOption)
&& mpValidationOptions.mp_permissionSMS[val]),
then: yup.string().required('Please enter your mobile number')
then: schema => schema.required('Please enter your mobile number')
.matches(phoneRegex, 'Please enter a valid UK mobile number')
}),

mp_phone: yup.string()
.when('mp_permissionPhone', {
is: val => (!(mpValidationOptions.mp_permissionPhone.disableOption)
&& mpValidationOptions.mp_permissionPhone[val]),
then: yup.string().required('Please enter your phone number')
then: schema => schema.required('Please enter your phone number')
.matches(phoneRegex, 'Please enter a valid UK phone number')
}),

mp_address1: yup.string()
.when('mp_permissionPost', {
is: val => (!(mpValidationOptions.mp_permissionPost.disableOption)
&& mpValidationOptions.mp_permissionPost[val]),
then: yup.string().required('Please enter the first line of your address')
then: schema => schema.required('Please enter the first line of your address')
.matches(/^[a-zA-Z0-9][a-zA-Z0-9'.,/()& -]*$/, 'This field only accepts alphanumeric characters and , . ( ) / & \' - and must start with an alphanumeric character')
.max(50, 'Please enter a maximum of 50 characters')
}),
Expand All @@ -100,21 +100,21 @@ const buildValidationSchema = overrideOptions => {
.when('mp_permissionPost', {
is: val => (!(mpValidationOptions.mp_permissionPost.disableOption)
&& mpValidationOptions.mp_permissionPost[val]),
then: yup.string().required('Please enter your town')
then: schema => schema.required('Please enter your town')
.matches(/^[a-zA-Z0-9][a-zA-Z0-9'.,/()& -]*$/, 'This field only accepts alphanumeric characters and , . ( ) / & \' - and must start with an alphanumeric character')
.max(50, 'Please enter a maximum of 50 characters')
}),

mp_postcode: yup.string().when('mp_permissionPost', {
is: val => (!(mpValidationOptions.mp_permissionPost.disableOption)
&& mpValidationOptions.mp_permissionPost[val]),
then: yup.string().required('Please enter your postcode').matches(/^[a-zA-Z]{1,2}\d[a-zA-Z\d]?\s*\d[a-zA-Z]{2}$/, 'Please enter a valid postcode')
then: schema => schema.required('Please enter your postcode').matches(/^[a-zA-Z]{1,2}\d[a-zA-Z\d]?\s*\d[a-zA-Z]{2}$/, 'Please enter a valid postcode')
}),

mp_country: yup.string().when('mp_permissionPost', {
is: val => (!(mpValidationOptions.mp_permissionPost.disableOption)
&& mpValidationOptions.mp_permissionPost[val]),
then: yup.string().required('Please enter your country')
then: schema => schema.required('Please enter your country')
.matches(/^[a-zA-Z0-9][a-zA-Z0-9'.,/()& -]*$/, 'This field only accepts alphanumeric characters and , . ( ) / & \' - and must start with an alphanumeric character')
.max(50, 'Please enter a maximum of 50 characters')
}),
Expand Down

0 comments on commit 76b2fdb

Please sign in to comment.