<% ' Regular expressions for validation functions (need to be same as in validation.js) const isNonblank_re = "\S" const isWhole_re = "^\s*\d+\s*$" const isInteger_re = "^\s*(\+|-)?\d+\s*$" const isDecimal_re = "^\s*(\+|-)?((\d+(\.\d+)?)|(\.\d+))\s*$" const isCurrency_re = "^\s*(\+|-)?((\d+(\.\d\d)?)|(\.\d\d))\s*$" const isEmail_re = "^\s*[\w\-\+_]+(\.[\w\-\+_]+)*\@[\w\-\+_]+\.[\w\-\+_]+(\.[\w\-\+_]+)*\s*$" dim creditCardList ' type prefix length creditCardList = array ( _ array ("amex", "34", 15), _ array ("amex", "37", 15), _ array ("disc", "6011", 16), _ array ("mc", "51", 16), _ array ("mc", "52", 16), _ array ("mc", "53", 16), _ array ("mc", "54", 16), _ array ("mc", "55", 16), _ array ("visa", "4", 13), _ array ("visa", "4", 16)) '----------------------------------------------------------- ' Helper functions ' Helper function for regular expressions function validateRE (s, regex) dim re set re = new regexp re.pattern = regex re.ignorecase = true validatere = re.test (s) set re = nothing end function ' Returns a string with all the non-digits removed function getdigits (s) dim re set re = new regexp re.pattern = "[^\d]" re.global = true getdigits = re.replace (s, "") set re = nothing end function ' Luhn checksum algorithm ' This assumes that all characters of cc are digits function luhn (cc) dim sum, i sum = 0 for i = len (cc) - 1 to 1 step -2 sum = sum + array (0, 2, 4, 6, 8, 1, 3, 5, 7, 9) (cint (mid (cc, i, 1))) next for i = len (cc) to 1 step -2 sum = sum + cint (mid (cc, i, 1)) next luhn = (sum mod 10 = 0) end function '----------------------------------------------------------- ' Helper functions. These all return true/false ' Check if string is non-blank function isNonblank (s) isNonblank = validateRE (s, isNonblank_re) end function ' Check if string is a whole number function isWhole (s) isWhole = validateRE (s, isWhole_re) end function ' Check if string is an integer function isInteger (s) isInteger = validateRE (s, isInteger_re) end function ' Check if string is decimal number function isDecimal (s) isDecimal = validateRE (s, isDecimal_re) end function ' Check if string is currency function isCurrency (s) isCurrency = validateRE (s, isCurrency_re) end function ' Check if string is a valid email address function isEmail (s) isEmail = validateRE (s, isEmail_re) end function ' Check for valid credit card number function isValidCC (cctype, ccnumber) dim cc, i cc = getdigits (ccnumber) if luhn (cc) then for i = 0 to ubound (creditCardList) if lcase (cctype) = creditCardList (i)(0) then if instr (cc, creditCardList (i)(1)) = 1 then if len (cc) = creditCardList (i)(2) then isValidCC = true exit function end if end if end if next end if isValidCC = false end function ' Check for valid ABA bank routing number function isValidABA (routingNumber) dim n, sum n = getdigits (routingnumber) if len (n) = 9 then sum = (cint (mid (n, 1, 1)) * 3) sum = sum + (cint (mid (n, 2, 1)) * 7) sum = sum + (cint (mid (n, 3, 1)) * 1) sum = sum + (cint (mid (n, 4, 1)) * 3) sum = sum + (cint (mid (n, 5, 1)) * 7) sum = sum + (cint (mid (n, 6, 1)) * 1) sum = sum + (cint (mid (n, 7, 1)) * 3) sum = sum + (cint (mid (n, 8, 1)) * 7) sum = sum + (cint (mid (n, 9, 1)) * 1) isValidABA = (sum mod 10 = 0) else isValidABA = false end if end function %>