944,097 Members | Top Members by Rank

Ad:
Aug 27th, 2006
0

javascript validation

Expand Post »
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.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
darylcharm is offline Offline
4 posts
since Aug 2006
Aug 28th, 2006
0

Re: javascript validation

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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
darylcharm is offline Offline
4 posts
since Aug 2006
Aug 28th, 2006
0

Re: javascript validation

try this

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

instead of this

/^ZPR\[0-9]$/
Reputation Points: 12
Solved Threads: 2
Light Poster
anuradhu is offline Offline
28 posts
since Apr 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in JavaScript / DHTML / AJAX Forum Timeline: Delay loading advertisements
Next Thread in JavaScript / DHTML / AJAX Forum Timeline: Alternating backgrounds?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC