1letters = new Array("a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"); 2numbers = new Array(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26); 3colors = new Array("FF","CC","99","66","33","00"); 4 5var endResult; 6 7function doTest() 8{ 9 endResult = ""; 10 11 // make up email address 12 for (var k=0;k<4000;k++) 13 { 14 name = makeName(6); 15 (k%2)?email=name+"@mac.com":email=name+"(at)mac.com"; 16 17 // validate the email address 18 var pattern = /^[a-zA-Z0-9\-\._]+@[a-zA-Z0-9\-_]+(\.?[a-zA-Z0-9\-_]*)\.[a-zA-Z]{2,3}$/; 19 20 if(pattern.test(email)) 21 { 22 var r = email + " appears to be a valid email address."; 23 addResult(r); 24 } 25 else 26 { 27 r = email + " does NOT appear to be a valid email address."; 28 addResult(r); 29 } 30 } 31 32 // make up ZIP codes 33 for (var s=0;s<4000;s++) 34 { 35 var zipGood = true; 36 var zip = makeNumber(4); 37 (s%2)?zip=zip+"xyz":zip=zip.concat("7"); 38 39 // validate the zip code 40 for (var i = 0; i < zip.length; i++) { 41 var ch = zip.charAt(i); 42 if (ch < "0" || ch > "9") { 43 zipGood = false; 44 r = zip + " contains letters."; 45 addResult(r); 46 } 47 } 48 if (zipGood && zip.length>5) 49 { 50 zipGood = false; 51 r = zip + " is longer than five characters."; 52 addResult(r); 53 } 54 if (zipGood) 55 { 56 r = zip + " appears to be a valid ZIP code."; 57 addResult(r); 58 } 59 } 60} 61 62function makeName(n) 63{ 64 var tmp = ""; 65 for (var i=0;i<n;i++) 66 { 67 var l = Math.floor(26*Math.random()); 68 tmp += letters[l]; 69 } 70 return tmp; 71} 72 73function makeNumber(n) 74{ 75 var tmp = ""; 76 for (var i=0;i<n;i++) 77 { 78 var l = Math.floor(9*Math.random()); 79 tmp = tmp.concat(l); 80 } 81 return tmp; 82} 83 84function addResult(r) 85{ 86 endResult += "\n" + r; 87} 88 89doTest(); 90