html
case4/back.jpg
case4/done.htm
case4/functions.js
/* New Perspectives on HTML, XHTML, and DHTML, 4th Edition Tutorial 14 Case Problem 4 Filename: functions.js Functions List: todayTxt() Displays the current date in the format mm/dd/yyyy. addCommas(value) Adds comma grouping to a numeric value (###,###,###.###). Returns a text string dollars(value) Converts a numeric value to a current format, including commas and the leading "$" symbol. Returns a text string. luhn(num) Returns a Boolean value indicating whether the number in the num text string fulfills the Luhn Formula. */ function todayTxt() { var Today=new Date(); return Today.getMonth()+1+"-"+Today.getDate()+"-"+Today.getFullYear(); } function addCommas(value) { valuetxt=value+""; decimals=""; re = /(-?\d+)(\d{3})/; decimalpos = valuetxt.search(/\./); if (decimalpos != -1) { decimals = "."+valuetxt.substring(decimalpos+1,valuetxt.length); valuetxt = valuetxt.substring(0,decimalpos); } while(re.test(valuetxt)) {valuetxt = valuetxt.replace(re,"$1,$2")} return valuetxt+=decimals; } function dollars(value) { n = Math.round(value*100)/100; if (n == Math.round(n)) {valuetxt=n+".00"} else if (n*10 == Math.round(n*10)) {valuetxt=n+"0"} else valuetxt=n+""; re = /(-?\d+)(\d{3})/; decimalpos = valuetxt.search(/\./); if (decimalpos != -1) { decimals = "."+valuetxt.substring(decimalpos+1,valuetxt.length); valuetxt = valuetxt.substring(0,decimalpos); } while(re.test(valuetxt)) {valuetxt = valuetxt.replace(re,"$1,$2")} return "$"+valuetxt+decimals; } function luhn(num) { var luhnTotal=0; for (i=num.length-1; i>=0; i--) { luhnTotal += parseInt(num.charAt(i)); i--; num2 = new String(num.charAt(i)*2); for (j=0; j < num2.length; j++) { luhnTotal += parseInt(num2.charAt(j)); } } return (luhnTotal % 10 == 0); }
case4/info.txt
Company ======= Wizard Works Fireworks 4311 Tower Street Ashland, KY 41105 (606) 555-3188 Link Names ========== Home Assortments Firecrackers Fountains Cones Rockets Sparklers Online Store Shopping Cart Your Account Safety Tech Support Customer Service About Us Contact Us Fountain Products ================= Green/Purple Fountain: $3.50 ea. Silver Cone: $4.95 ea. Glitter Cone: $6.95 ea. Glittering Stars: $9.95 ea. Fountain Kit: $19.95 ea. Fountain Kit Deluxe: $29.95 Giant Fountain: $39.95 Regular Expressions =================== Integers 0 or greater /^\d+$/ General Phone Numbers /^\(?\d{3}[\)-]?\s?\d{3}[\s-]?\d{4}$/ All occurences of white Space /\s/g American Express /^3[47]\d{13}$/ Diners Club /^30[0-5]\d{11}$|^3[68]\d{12}$/ Discover Card /^6011\d{12}$/ MasterCard /^5[1-5]\d{14}$/ Visa /^4(\d{12}|\d{15})$/