Search
 
SCRIPT & CODE EXAMPLE
 

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);
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: Add an item to the beginning of an Array 
Javascript :: export component react 
Javascript :: javascript download html to pdf 
Javascript :: json deep dot 
Javascript :: convert json object to lowercase 
Javascript :: how to copy text from input through button click js 
Javascript :: react buffer to image 
Javascript :: react hide element 
Javascript :: document.print js 
Javascript :: join array of objects javascript 
Javascript :: install Angular Material and Angular Animations using the following command 
Javascript :: vuex getters 
Javascript :: socket emit to specific room using nodejs socket.io 
Javascript :: js event on change focus 
Javascript :: logic operators in javascript 
Javascript :: completablefuture async example 
Javascript :: get react form input data, How get form input data in react 
Javascript :: google jquery 3.5.1 
Javascript :: validate form on submit 
Javascript :: json loop in js 
Javascript :: Redux thunk and react redux 
Javascript :: ssr full form in nextjs 
Javascript :: javascript var,let,const compare 
Javascript :: jest add alias 
Javascript :: javascript null check 
Javascript :: substring methods example 
Javascript :: resize image in node.js 
Javascript :: get url of page in background script 
Javascript :: how to make page scroll to the top jsx 
Javascript :: hex decima to binary js 
ADD CONTENT
Topic
Content
Source link
Name
5+2 =