Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / chrome / test / data / dromaeo / tests / sunspider-string-validate-input.html
blob1efc80ae27f1902df22d516c9a3dcebcadf0ef02
1 <html>
2 <head>
3 <script src="../htmlrunner.js"></script>
4 <script>
5 var letters = 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");
6 var numbers = 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);
7 var colors = new Array("FF","CC","99","66","33","00");
9 var endResult;
11 function testEmail()
13 endResult = "";
14 var r;
16 // make up email address
17 for (var k=0;k<2000;k++)
19 var name = makeName(6);
20 var email = (k%2)?name+"@mac.com":name+"(at)mac.com";
22 // validate the email address
23 var pattern = /^[a-zA-Z0-9\-\._]+@[a-zA-Z0-9\-_]+(\.?[a-zA-Z0-9\-_]*)\.[a-zA-Z]{2,3}$/;
25 if(pattern.test(email))
27 r = email + " appears to be a valid email address.";
28 addResult(r);
30 else
32 r = email + " does NOT appear to be a valid email address.";
33 addResult(r);
38 function testZip()
40 endResult = "";
41 var r;
43 // make up ZIP codes
44 for (var s=0;s<2000;s++)
46 var zipGood = true;
47 var zip = makeNumber(4);
48 (s%2)?zip=zip+"xyz":zip=zip.concat("7");
50 // validate the zip code
51 for (var i = 0; i < zip.length; i++) {
52 var ch = zip.charAt(i);
53 if (ch < "0" || ch > "9") {
54 zipGood = false;
55 r = zip + " contains letters.";
56 addResult(r);
59 if (zipGood && zip.length>5)
61 zipGood = false;
62 r = zip + " is longer than five characters.";
63 addResult(r);
65 if (zipGood)
67 r = zip + " appears to be a valid ZIP code.";
68 addResult(r);
73 function makeName(n)
75 var tmp = "";
76 for (var i=0;i<n;i++)
78 var l = Math.floor(26*Math.random());
79 tmp += letters[l];
81 return tmp;
84 function makeNumber(n)
86 var tmp = "";
87 for (var i=0;i<n;i++)
89 var l = Math.floor(9*Math.random());
90 tmp = tmp.concat(l);
92 return tmp;
95 function addResult(r)
97 endResult += "\n" + r;
100 window.onload = function(){ startTest("sunspider-string-validate-input", '7e409a49');
102 test("Validate Email Input", testEmail);
103 test("Validate Zipcode Input", testEmail);
105 endTest(); };
106 </script>
107 </head>
108 <body></body>
109 </html>