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

206
Views
cómo crear expresiones regulares para (-) no repetir después de 3 dígitos dentro de formik setfieldvalue

tengo una función regex como esta:

 const format = (value) => { if (typeof value === 'string') { return value.replace(/(\d{3})(\d+)/g, '$1-$2'); } }

cuando consuelo sin ingresar en formik setfieldvalue, produce expresiones regulares correctas como 111-1111111:

 const custom = (value) => { console.log('valuemain',format(value)); //this valuemain: 111-1111111 formikRef.current.setFieldValue('customnumb',value) }

pero cuando ingreso expresiones regulares en formik setfieldvalue se vuelve como 111-111-111:

 const custom = (value) => { console.log('valuemain',format(value)); //this valuemain: 111-111-111 formikRef.current.setFieldValue('customnumb',format(value)) }
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Reemplace de antemano todas las apariciones del guión "-" con "" ( cadena vacía )

 const format = (val = "") => val.replace(/-/g, "").replace(/(\d{3})(\d+)/g, '$1-$2'); console.log(format("1111111111")); // "111-1111111" console.log(format("111-1111111")); // "111-1111111" console.log(format("111-11-1-1-1-11")); // "111-1111111"

Como obviamente solo te interesan los números enteros ; para ser políticamente más correcto, en lugar de reemplazar solo los guiones "-" , podría reemplazar (usando RegExp \D Not a Digit ) — todo lo que no sea un dígito :

 const format = (val = "") => { // @TODO: do val checks if needed here. return val .replace(/\D/g, "") // Remove everything that is not a digit .replace(/(\d{3})(\d+)/g, '$1-$2'); // Format as desired }; console.log(format("1111111111")); // "111-1111111" console.log(format("111-1111111")); // "111-1111111" console.log(format("111-11-1-1-1-11")); // "111-1111111"

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!