Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR HTML

check input length

//Use the code below to set min and max characters for an input
//grabbing element from the DOM
const username = document.getElementById('username');

function checkLength(input, min, max) {
  if(input.value.length < min)
  {//below can be applied to a field, etc
    console.log(`${input.id} must be at least ${min} characters`)
  }
  else if(input.value.length > max){
    console.log(`${input.id} must be less than ${max} characters`)
  }
}
//call function
checkLength(username, 3, 15)
 
PREVIOUS NEXT
Tagged: #check #input #length
ADD COMMENT
Topic
Name
8+8 =