Skip to content

Instantly share code, notes, and snippets.

@surajp
Last active July 5, 2019 00:11
Show Gist options
  • Save surajp/10f2a286840f88cda2fbbb82950d4a1f to your computer and use it in GitHub Desktop.
Save surajp/10f2a286840f88cda2fbbb82950d4a1f to your computer and use it in GitHub Desktop.
Regex validation for JSON Array
const colheaders = Object.keys(rows[0]);
const errors=[];
const regexpArray=[];
rows.forEach((row,rowindex)=>{
errors[rowindex]=[];
Object.values(row).forEach((val,colindex)=>{
if(regexpArray[colindex] && regexpArray[colindex].test(val)){
errors[rowindex].push(colheaders[colindex]);
}
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment