4
Copyright (C) 2007 Apple Inc. All rights reserved.
6
Redistribution and use in source and binary forms, with or without
7
modification, are permitted provided that the following conditions
9
1. Redistributions of source code must retain the above copyright
10
notice, this list of conditions and the following disclaimer.
11
2. Redistributions in binary form must reproduce the above copyright
12
notice, this list of conditions and the following disclaimer in the
13
documentation and/or other materials provided with the distribution.
15
THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
16
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18
PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
19
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
20
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
22
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
23
OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
<title>SunSpider string-validate-input</title>
33
<h3>string-validate-input</h3>
39
var _sunSpiderStartDate = new Date();
41
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");
42
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);
43
colors = new Array("FF","CC","99","66","33","00");
51
// make up email address
52
for (var k=0;k<4000;k++)
55
(k%2)?email=name+"@mac.com":email=name+"(at)mac.com";
57
// validate the email address
58
var pattern = /^[a-zA-Z0-9\-\._]+@[a-zA-Z0-9\-_]+(\.?[a-zA-Z0-9\-_]*)\.[a-zA-Z]{2,3}$/;
60
if(pattern.test(email))
62
var r = email + " appears to be a valid email address.";
67
r = email + " does NOT appear to be a valid email address.";
73
for (var s=0;s<4000;s++)
76
var zip = makeNumber(4);
77
(s%2)?zip=zip+"xyz":zip=zip.concat("7");
79
// validate the zip code
80
for (var i = 0; i < zip.length; i++) {
81
var ch = zip.charAt(i);
82
if (ch < "0" || ch > "9") {
84
r = zip + " contains letters.";
88
if (zipGood && zip.length>5)
91
r = zip + " is longer than five characters.";
96
r = zip + " appears to be a valid ZIP code.";
105
for (var i=0;i<n;i++)
107
var l = Math.floor(26*Math.random());
113
function makeNumber(n)
116
for (var i=0;i<n;i++)
118
var l = Math.floor(9*Math.random());
124
function addResult(r)
126
endResult += "\n" + r;
132
var _sunSpiderInterval = new Date() - _sunSpiderStartDate;
134
document.getElementById("console").innerHTML = _sunSpiderInterval;