Ported Version of validatejs f

Currently unmaintained since I have moved from Microfocus Service Manager to ServiceNow - Sorry guys!

servicemanager-validatejs

This is the port of https://github.com/ansman/validate.js.

The difference between the original version and this one is the removed async functionality. Also we added Underscore.js to replace some native js functionality like map, forEach and filter, because the Service Manager has an old JS Engine.

Documentation

You can find the full documentation here: https://validatejs.org/#validate-js

Usage Create a new ScriptLibrary named validatejs Copy the content (Source or Minified Version) into the created ScriptLibrary Create a new ScriptLibrary named validatejs_test with the following content

var validate = system.library.validatejs.require(); //presence example var resPresense1 = validate({input: ""}, {input: {presence: {allowEmpty: false}}}); print(resPresense1.toSource()); // => {"input:" ["Input can't be blank"]} var resPresense2 = validate({}, {username: {presence: {message: "is required"}}}); print(resPresense2.toSource()); // => {"username": ["Username is required"]} // format example var constraintsFormat = { username: { format: { pattern: "[a-z0-9]+", flags: "i", message: "can only contain a-z and 0-9" } } }; var resFormatInvalid = validate({username: "Nicklas!"}, constraintsFormat); print(resFormatInvalid.toSource()); // => {"username": ["Username can only contain a-z and 0-9"]} var resFormatValid = validate({username: "Nicklas"}, constraintsFormat); print(resFormatValid.toSource()); // => undefined // custom validations validate.validators.custom = function(value, options, key, attributes) { print(value); print(options); print(key); print(attributes); return "is totally wrong"; }; var resCustom = validate({foo: "some value"}, {foo: {custom: "some options"}}); print(resCustom.toSource());

版权声明:

1、该文章(资料)来源于互联网公开信息,我方只是对该内容做点评,所分享的下载地址为原作者公开地址。
2、网站不提供资料下载,如需下载请到原作者页面进行下载。