How to use the @ncform/ncform-common.ncformUtils function in @ncform/ncform-common

To help you get started, we’ve selected a few @ncform/ncform-common examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ncform / ncform / packages / ncform / src / rules / pattern.js View on Github external
import ncformCommon from "@ncform/ncform-common";

const { notEmptyVal, getValType } = ncformCommon.ncformUtils;
const { ValidationRule } = ncformCommon;

class PatternRule extends ValidationRule {
  constructor(props) {
    super(props);
    this.name = "pattern";
    this.defaultErrMsg = "pattern validate error";
  }

  validateLogic(val, ruleVal) {
    if (!notEmptyVal(ruleVal) && getValType(ruleVal) !== "regexp") return true;

    if (getValType(ruleVal) === "string") ruleVal = new RegExp(ruleVal);

    return ruleVal.test(val);
  }