legalize.jsPayPal 验证对象库
legalize.js 是 PayPal 用来执行对象验证的库。
示例代码:
var personSchema = { firstName: Legalize.string().minLength(1).maxLength(30).required(), lastName: Legalize.string().minLength(1).maxLength(30).required(), age: Legalize.number().integer().min(18), sex: Legalize.string().sanitizeBefore(function (value) { value.toLowerCase(); }).valid("male", "female").optional(), };var validationResult = Legalize.validate({ firstName: "Alexander", lastName: "Carnicero", age: 27}, personSchema);if (validationResult.error) { // report error here} else { validationResult.warnings.forEach(function (warning) { // report warning }); // validationResult.value contains validated value}
评论