Best web site - 1305Chapter 50 .Application: A Lookup Table Now comes
Wednesday, December 26th, 20071305Chapter 50 .Application: A Lookup Table Now comes the beginning of the data validation functions. Under control of a master validation function shown in a minute, the stripZeros() function removes any leading 0s that the user may have entered. Notice that the instructions tell the user to enter the first three digits of a Social Security number. For 001 through 099, that means the numbers begin with one or two 0s. JavaScript, however, treats any numeric value starting with 0 as an octal value. Because I have to do some numeric comparisons for the search through the ssn[]array, the script must make sure that the entries (which are strings to begin with, coming as they do from text objects) can be converted to decimal numbers. The parseInt() function, with the all-important second parameter indicating Base 10 numbering, does the job. But because the remaining validations assume a string value, the integer is reconverted to a string value before it is returned. // **BEGIN DATA VALIDATION FUNCTIONS** // JavaScript sees numbers with leading zeros as octal values, // so strip zeros function stripZeros(inputStr) { return parseInt(inputStr, 10).toString() } The next three functions are described in full in Chapter 43, which discusses data validation. In the last function, a copy of the input value is converted to an integer to enable the function to make necessary comparisons against the boundaries of acceptable ranges. // general purpose function to see if an input value has been entered // at all function isEmpty(inputStr) { if (inputStr == null || inputStr == ) { return true } return false } // general purpose function to see if a suspected numeric input // is a positive integer function isNumber(inputStr) { for (var i = 0; i < inputStr.length; i++) { var oneChar = inputStr.charAt(i) if (oneChar < 0 || oneChar > 9 ) { return false } } return true } // function to determine if value is in acceptable range for this // application function inRange(inputStr) { num = parseInt(inputStr) if (num < 1 || (num > 586 && num < 596) || (num > 599 && num < 700) || num > 728) { return false } return true }
We recommend you use shared web hosting services, because many users agree that it is cheap, reliable and customer-satisfying webhost.