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.

Call validate methods by code

See original GitHub issue

Using vee-validate to validate some string dynamically by code, such as

VeeValidate.validate( 'max:6|min:2', 4 )

This function is very useful for most case, how to implement it?

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
logaretmcommented, Aug 11, 2018

Thanks for the suggestion and patience, the feature is now introduced as verify method which works like this:

import { Validator } from 'vee-validate';

const v = new Validator();
const { valid, errors } = await v.verify('test', 'max:3');

// the valid prop indicates the result of validation.
console.log(valid); // false

// The `errors` is an array of error strings.
console.log(errors); // ["The {field} field may not be greater than 3 characters."]

Note that the messages returned will have {field} as the field name so you can replace it easily if you need to.

The errors array will be empty if the validation passes. This will be available in the next release.

0reactions
nicolasvahidzeincommented, Aug 14, 2018

I was so happy i misread, you said next release, do you know when that will be?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Writing Validation Code in the validateEntity Method
To write entity-level validation code, enter the protected validateEntity() method in your entity object's class file, call super.validateEntity(), and then ...
Read more >
Chapter 3. Declaring and validating method constraints
In the remainder of this chapter you will learn how to declare parameter and return value constraints and how to validate them using...
Read more >
Method Constraints with Bean Validation 2.0 - Baeldung
In this article, we'll discuss how to define and validate method constraints using Bean Validation 2.0 (JSR-380). In the previous article, ...
Read more >
Best practice: Validate conditions for method calls?
The general rule is not to validate the input more than necessary. If something isn't valid, you should throw a exception (C#), or...
Read more >
Should a method validate its parameters? [duplicate]
I always use the simple scheme : UI and simple code to call methods (Validate UI parameters) -> Methods (validates not UI parameters) ......
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