Is there a way to stop inserting an undefined value in MYSQL using reactjs?
so here is the code.
const regex = /.*([A-Za-z0-9_\-]{11}).*/gi;
if (postData.video_id) {
postData.video_id = postData.video_id.replace(regex, "$1");
}
and it keeps submitting undefined in the database, I need to make it optional either with value or empty, it is up to the user.
appreciate your help
the data might do not match with the regex, so
validate the replace expression before assign it to postData.video_id :
const regex = /.*([A-Za-z0-9_\-]{11}).*/gi;
if (postData.video_id) {
const videoId = postData.video_id.replace(regex, "$1");
if(videoId) postData.video_id = videoId;
}