hi i am new in javascript, can somebody please assist me on how to to this validation:

starts with ZPR 11 characters(the rest will be numbers only)
total of 3 characters and 8 numbers

thank you for your time guys.

Recommended Answers

All 2 Replies

hi again! i ran into a tutorial for javascript regarding: Regxp, then i came up with this code

} else if(name = /^ZPR\[0-9]$/) {
      hideAllErrors();
      document.getElementById("nameError").style.display = "inline";
      document.getElementById("name").select();
    return false;

but it doesnt work, can somebody please guide me accordingly?

below is my current validation.js

function checkForm() {
    
  name = document.getElementById("name").value;
  email = document.getElementById("email").value;
 
  if (name == "") {
  hideAllErrors();
document.getElementById("nameError").style.display = "inline";
document.getElementById("name").select();
  return false;
  } else if (email == "") {
hideAllErrors();
document.getElementById("emailError").style.display = "inline";
document.getElementById("email").select();
  return false;
  } else if (email.indexOf("@") < 1) { //  must contain @, and it must not be the first character
hideAllErrors();
document.getElementById("emailError").style.display = "inline";
document.getElementById("email").select();
  return false;
  } else if (email.lastIndexOf(".") <= email.indexOf("@")) {  // last dot must be after the @
hideAllErrors();
document.getElementById("emailError").style.display = "inline";
document.getElementById("email").select();
  return false;  
  } else if (email.indexOf("@") == email.length) {  // @ must not be the last character
hideAllErrors();
document.getElementById("emailError").style.display = "inline";
document.getElementById("email").select();
  return false;  
  } else if (email.indexOf("..") >=0) { // two periods in a row is not valid
hideAllErrors();
document.getElementById("emailError").style.display = "inline";
document.getElementById("email").select();
  return false; 
  } else if (email.indexOf(".") == email.length) {  // . must not be the last character
hideAllErrors();
document.getElementById("emailError").style.display = "inline";
document.getElementById("email").select();
  return false; 
  
  }
  return true;
  }
 
  function hideAllErrors() {
document.getElementById("nameError").style.display = "none"
document.getElementById("emailError").style.display = "none"

  }

try this

/^ZPR[0-9]{8}$/

instead of this

/^ZPR\[0-9]$/

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.