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

420
Views
¡Ayuda con el formato de validación de formularios! (Sin mayúsculas, sin números, sin espacios, sin símbolos especiales...)

Tengo una validación de formulario básica en este momento en Javascript en este momento. ¿Cómo lo formateo para que todo lo que se escriba en el campo de entrada DEBE ser:

  • Mayúsculas
  • No hay espacios
  • No más de 5 caracteres
  • Ninguno de los siguientes símbolos especiales: !@#$%^&*()-_+=][{}|'”:;?/><,~`
  • Sin números

JavaScript:

 function stockValidate() { let x = document.getElementById("inputText3").value; let text; if FORMATTING HERE { text = "Input not valid"; document.getElementById("inputText3").value = ''; } else { text = "Input OK"; } document.getElementById("demo").innerHTML = text; }

HTML:

 <div class="col-auto"> <input type="text" id="inputText3" class="form-control" aria-describedby="TextHelpInline" placeholder="eg AAPL"/> </div> <div class="col-auto"> <button id="inputTextBtn3" class="btn set-btn" onclick="stockValidate()">Add</button> </div> <p id="demo"></p>
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Intentaría esa forma de resolver el problema:

Agregar validación solo para letras mayúsculas y números

Dado que incluyó su código html, incluso llamaría a la forma en que usa el atributo de patrón la forma simple de hacer esta validación.

PD: https://www.w3schools.com/tags/att_input_pattern.asp

about 4 years ago · Juan Pablo Isaza Report

0

Según los consejos de @Graficode, aquí está el código final:

 function stockValidate() { var specialChars = /[`!@#$%^&*()_+\-=\[\]{};':"\\|,<>\/?~]/; let x = document.getElementById("inputText3").value; let text; if (x.toUpperCase() != x) { document.getElementById('demo').style.display = "block"; text = "Stock symbol must be uppercase"; document.getElementById("inputText3").value = ''; } else if (x === '') { document.getElementById('demo').style.display = "block"; text = "No blanks" } else if (x.includes(' ')) { text = "No spaces"; document.getElementById('demo').style.display = "block"; document.getElementById("inputText3").value = ''; } else if (x.length > 5) { document.getElementById('demo').style.display = "block"; text = "No more than 5 characters"; document.getElementById("inputText3").value = ''; } else if (/\d/.test(x)) { document.getElementById('demo').style.display = "block"; text = "No numbers allowed"; document.getElementById("inputText3").value = ''; } else if (specialChars.test(x)) { document.getElementById('demo').style.display = "block"; text = "No special characters allowed"; document.getElementById("inputText3").value = ''; } else { text = "Input OK"; document.getElementById('demo').style.display = "none"; } document.getElementById("demo").innerHTML = text; }
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!