question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

docs: Validator.register(...) `requirement` parameter

See original GitHub issue

In the Validator.register block, what does the requirement parameter represent?

Validator.register('telephone', function(value, requirement, attribute) { // requirement parameter defaults to null
  return value.match(/^\d{3}-\d{3}-\d{4}$/);
}, 'The :attribute phone number is not in the format XXX-XXX-XXXX.');

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
AhmedWaelElsawycommented, Dec 13, 2020

@mikeerickson thanks very much

1reaction
mikeericksoncommented, Dec 13, 2020

@AhmedWaelElsawy The req value will contain any information after the semicolon in custom validation rule

With a custom rule as

Validator.register("years", function (val, req, attrs) {
        console.log(val, req, attrs);
        return val.length === parseInt(req)
      });
...
const validator = new Validator({ digits: "2020" }, { digits: "years:4" });

When you call execute validator, the req parameter would be 4 in this case

====

here is a test from validatorjs project

it("should should handle numeric rule", function () {
  Validator.register("years", function (val, req, attrs) {
    return val.length === parseInt(req);
  });

  const validator = new Validator({ digits: "2020" }, { digits: "years:4" });
  expect(validator.passes()).to.be.true;
});
Read more comments on GitHub >

github_iconTop Results From Across the Web

docs: Validator.register(...) `requirement` parameter · Issue #271
In the Validator.register block, what does the requirement parameter represent? Validator.register('telephone', function(value, requirement, ...
Read more >
Chapter 6. Creating custom constraints
To create a custom constraint, the following three steps are required: Create a constraint annotation; Implement a validator; Define a default error message ......
Read more >
Validators | Blockly - Google Developers
A validator is a function that takes in the fields new value, and then acts on it. They are a simple way to...
Read more >
Validation — dynaconf 2.2.3 documentation - Read the Docs
from dynaconf import settings, Validator # Register validators ... Ensure some parameters exists (are required) Validator('VERSION', 'AGE', 'NAME', ...
Read more >
Validation - Dynaconf - 3.1.11
Instead of passing validators= argument to Dynaconf class you can register validators after the instance is created. settings = Dynaconf(.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found