javascript validation

Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Reply

Join Date: Aug 2006
Posts: 4
Reputation: darylcharm is an unknown quantity at this point 
Solved Threads: 0
darylcharm darylcharm is offline Offline
Newbie Poster

javascript validation

 
0
  #1
Aug 27th, 2006
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.
Reply With Quote Quick reply to this message  
Join Date: Aug 2006
Posts: 4
Reputation: darylcharm is an unknown quantity at this point 
Solved Threads: 0
darylcharm darylcharm is offline Offline
Newbie Poster

Re: javascript validation

 
0
  #2
Aug 28th, 2006
hi again! i ran into a tutorial for javascript regarding: Regxp, then i came up with this code
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. } else if(name = /^ZPR\[0-9]$/) {
  2. hideAllErrors();
  3. document.getElementById("nameError").style.display = "inline";
  4. document.getElementById("name").select();
  5. return false;

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

below is my current validation.js
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. function checkForm() {
  2.  
  3. name = document.getElementById("name").value;
  4. email = document.getElementById("email").value;
  5.  
  6. if (name == "") {
  7. hideAllErrors();
  8. document.getElementById("nameError").style.display = "inline";
  9. document.getElementById("name").select();
  10. return false;
  11. } else if (email == "") {
  12. hideAllErrors();
  13. document.getElementById("emailError").style.display = "inline";
  14. document.getElementById("email").select();
  15. return false;
  16. } else if (email.indexOf("@") < 1) { // must contain @, and it must not be the first character
  17. hideAllErrors();
  18. document.getElementById("emailError").style.display = "inline";
  19. document.getElementById("email").select();
  20. return false;
  21. } else if (email.lastIndexOf(".") <= email.indexOf("@")) { // last dot must be after the @
  22. hideAllErrors();
  23. document.getElementById("emailError").style.display = "inline";
  24. document.getElementById("email").select();
  25. return false;
  26. } else if (email.indexOf("@") == email.length) { // @ must not be the last character
  27. hideAllErrors();
  28. document.getElementById("emailError").style.display = "inline";
  29. document.getElementById("email").select();
  30. return false;
  31. } else if (email.indexOf("..") >=0) { // two periods in a row is not valid
  32. hideAllErrors();
  33. document.getElementById("emailError").style.display = "inline";
  34. document.getElementById("email").select();
  35. return false;
  36. } else if (email.indexOf(".") == email.length) { // . must not be the last character
  37. hideAllErrors();
  38. document.getElementById("emailError").style.display = "inline";
  39. document.getElementById("email").select();
  40. return false;
  41.  
  42. }
  43. return true;
  44. }
  45.  
  46. function hideAllErrors() {
  47. document.getElementById("nameError").style.display = "none"
  48. document.getElementById("emailError").style.display = "none"
  49.  
  50. }
Last edited by darylcharm; Aug 28th, 2006 at 1:04 am.
Reply With Quote Quick reply to this message  
Join Date: Apr 2006
Posts: 28
Reputation: anuradhu is an unknown quantity at this point 
Solved Threads: 2
anuradhu anuradhu is offline Offline
Light Poster

Re: javascript validation

 
0
  #3
Aug 28th, 2006
try this

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

instead of this

/^ZPR\[0-9]$/
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC