Git Product home page Git Product logo

servicemanager-validatejs's Introduction

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

  1. Create a new ScriptLibrary named validatejs
  2. Copy the content (Source or Minified Version) into the created ScriptLibrary
  3. 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());


servicemanager-validatejs's People

Contributors

noxify avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Forkers

skay19 konni7wa

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.