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

421
Views
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 answers
Answer question

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 Report

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