Would you like to clone this notebook?

When you clone a notebook you are able to make changes without affecting the original notebook.

Cancel

ajv #1880

node v14.20.1
version: master
endpointsharetweet
var Ajv = require('ajv'); var ajv = new Ajv({ // options here discriminator: true, formats: { email: /^[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$/i } }); // it also did not work for me when I call // ajv.addFormat("email", <regex>) function validateSchema(args, schema) { if(!schema.$id) throw Error("id missing") // if I call ajv.addFormat("email", <regex>) here, it works const validate = ajv.getSchema(schema.$id) || ajv.compile(schema) const isValid = validate(args) if(isValid) return {isValid: true} else { return { isValid: false, errors: validate.errors } } } const signUpArgsSchema = { type: "object", $id: "signUpArgsSchema", properties: { email: {type: "string", format: "email"} }, required: ["email"], additionalProperties: false } console.log(validateSchema({email: "qweqwe@test.com"}, signUpArgsSchema));
Loading…

no comments

    sign in to comment