3 <script src=
"../htmlrunner.js"></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");
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.";
32 r
= email
+ " does NOT appear to be a valid email address.";
44 for (var s
=0;s
<2000;s
++)
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") {
55 r
= zip
+ " contains letters.";
59 if (zipGood
&& zip
.length
>5)
62 r
= zip
+ " is longer than five characters.";
67 r
= zip
+ " appears to be a valid ZIP code.";
78 var l
= Math
.floor(26*Math
.random());
84 function makeNumber(n
)
89 var l
= Math
.floor(9*Math
.random());
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
);