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

426
Vistas
Form validation formatting help! (No uppercase, no numbers, no spaces, no special symbols..)

I have a basic form validation right now in Javascript right now. How do I format it so that whatever is typed in the input field MUST be:

  • Uppercase
  • No spaces
  • No more than 5 characters
  • None of the following special symbols: !@#$%^&*()-_+=][{}|’”:;?/><,~`
  • No numbers

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="e.g. 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 Respuestas
Responde la pregunta

0

I would try that way of solving the issue:

Add validation only for capital letter and numbers

Since you included your html code I would even call the way using the pattern-attribute the simple way to do this validation.

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

about 4 years ago · Juan Pablo Isaza Denunciar

0

As per @Graficode's tips, here is the final code:

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 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