DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/)
-   JavaScript / DHTML / AJAX (http://www.daniweb.com/forums/forum117.html)
-   -   javascript validation (http://www.daniweb.com/forums/thread53526.html)

darylcharm Aug 27th, 2006 11:34 pm
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 Aug 28th, 2006 12:49 am
Re: javascript validation
 
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"

  }

anuradhu Aug 28th, 2006 7:38 am
Re: javascript validation
 
try this

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

instead of this

/^ZPR\[0-9]$/


All times are GMT -4. The time now is 9:37 am.

Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC