Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

402
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda