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

71
Views
Limitar saltos de línea en textarea

Tengo un área de texto, donde quiero permitir que los usuarios hagan saltos de línea presionando Intro, pero quiero limitar eso a solo un salto, porque entonces los usuarios podrían agregar tantos saltos como quieran, creando un gran espacio en blanco en la salida. .

 <textarea maxLength={3000} onChange={(e) => setPersonBio(e.target.value)} value={personBio} type="text" rows="5" className="bio-content" placeholder="Enter something about yourself..."></textarea>

Y luego lo muestro en la etiqueta <p> con white-space: pre-line;

Mi pregunta es cómo limitar la cantidad de pausas que el usuario puede ingresar o eliminar las adicionales después de enviarlas.

about 4 years ago · Santiago Trujillo
2 answers
Answer question

0

Puede usar la search de métodos de String e include dentro de un ciclo while para eliminar todos menos uno de un carácter repetido dado.

 text = "abc\n\n\ndef\n\nghi"; document.write('<textarea rows=6>'+text+'</textarea>'); while (text.includes("\n\n")) text = text.replace("\n\n","\n"); document.write('<textarea rows=6>'+text+'</textarea>');

about 4 years ago · Santiago Trujillo Report

0

Podrías intentar esto:

 <textarea maxLength={3000} onChange=textAreaChange(e) value={personBio} type="text" rows="5" className="bio-content" placeholder="Enter something about yourself..."></textarea>
 var pre=""; function textAreaChange(e){ if(e.target.value.split("\n").length>1){ e.target.value=pre; return; }; setPersonBio(e.target.value); pre=e.target.value; };

Agregue el javascript donde guarda todos sus otros javascript para este sitio.

about 4 years ago · Santiago Trujillo 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!