954,193 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

javascript validation

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.

darylcharm
Newbie Poster
4 posts since Aug 2006
Reputation Points: 10
Solved Threads: 0
 

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"

  }
darylcharm
Newbie Poster
4 posts since Aug 2006
Reputation Points: 10
Solved Threads: 0
 

try this

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

instead of this

/^ZPR\[0-9]$/

anuradhu
Light Poster
29 posts since Apr 2006
Reputation Points: 12
Solved Threads: 2
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You