Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

yup string date schema validation

//take a string as a date, and check it is a valid date
const schema = yup.object().shape({
  start: yup.string().label('start date').test(dateString => new Date(dateString).toString() !== 'Invalid Date'),
});

const obj = {
 id: 234,
 start: "2022-11-15 08:53:00",
}

try {
  schema.validateSync(obj);
  console.log("success");
} catch (err) {
  console.error(err.name, err.errors);
}
 
PREVIOUS NEXT
Tagged: #yup #string #date #schema #validation
ADD COMMENT
Topic
Name
6+7 =