Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

389
Views
Cómo validar usando yup para verificar la longitud mínima de la cadena, la longitud máxima y permitir el vacío
firstName: yup .string() .test( 'len', 'can be empty or with string at least 2 characters and not more than 10', (val) => val != undefined && (val.length == 0 || (val.length >= 2 && val.length <= 10) ) )

en este caso, la longitud min 2 y max 10 funciona, pero cuando está vacío se marca con un error, lo intenté con val.length == 0

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

arreglado por cheque indefinido separado

 firstName: yup .string() .test( 'len', 'can be empty or with string at least 2 characters and not more than 10', (val) => { if (val == undefined) { return true; } return ((val.length == 0 || (val.length >= 2 && val.length <= 10))) } ),
about 4 years ago · Juan Pablo Isaza Report

0

hola se puede hacer asi

 const yup = require("yup"); const firstName = ""; const schema = yup .string() .test( "len", "can be empty or with string at least 2 characters and not more than 10", (val) => { if (val === undefined) { return true; } return val.length === 0 || (val.length >= 2 && val.length <= 10); } ); schema .validate(firstName) .then((response) => console.log(response)) .catch((err) => console.log(err));

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!