TAILIEUCHUNG - JavaScript Bible, Gold Edition part 133

JavaScript Bible, Gold Edition part 133. This book will bring programmers and non-technical professionals, including casual programmers and scripters, painlessly up to speed on all aspects of mastering JavaScript. Key topics include programming fundamentals, JavaScript language elements and how to use them effectively, and how to easily and efficiently add powerful new functionality to HTML documents and Java applets. | 1168 Part V Putting JavaScript to Work Listing 43-13 Date Range Validations Date Minus 90 Minus 20 function isM90_M20Date if 0 return true var thisYear getTheYear return isDate thisYear - 90 thisYear - 20 Date Minus 70 Minus 0 function isM70_0Date if 0 return true var thisYear getTheYear return isDate thisYear - 70 thisYear Date Minus 5 Plus 10 function isM5_P10Date if 0 return true var thisYear getTheYear return isDate thisYear - 5 thisYear 10 The naming convention I create for the functions includes the two range components relative to the current date. A letter M means the range boundary is minus a number of years from the current date P means the range is plus a number of years. If the boundary should be the current year a zero is used. Therefore the isM5_P10Date function performs range checking for boundaries between 5 years before and 10 years after the current year. Before performing any range checking each function makes sure there is some value to validate. If the field entry is empty the function returns true. This is fine here because dates are not required when the data is unknown. Next the functions get the current four-digit year. The code here had to work originally with browsers that did not have the getFullYear method available yet. Therefore the Y2K fix described in Chapter 36 was built into the application function getTheYear var thisYear new Date .getYear thisYear thisYear 100 thisYear 1900 thisYear return thisYear The final call from the range validations is to a common isDate function which handles not only the date range validation but also the validation for valid dates for example making sure that September has only 30 days . Listing 43-14 shows this monster-sized function. Because of the length of this function I interlace commentary within the code listing. Chapter 43 Data-Entry Validation 1169 Listing 43-14 Primary Date Validation Function date field validation called by other .

TỪ KHÓA LIÊN QUAN
TAILIEUCHUNG - Chia sẻ tài liệu không giới hạn
Địa chỉ : 444 Hoang Hoa Tham, Hanoi, Viet Nam
Website : tailieuchung.com
Email : tailieuchung20@gmail.com
Tailieuchung.com là thư viện tài liệu trực tuyến, nơi chia sẽ trao đổi hàng triệu tài liệu như luận văn đồ án, sách, giáo trình, đề thi.
Chúng tôi không chịu trách nhiệm liên quan đến các vấn đề bản quyền nội dung tài liệu được thành viên tự nguyện đăng tải lên, nếu phát hiện thấy tài liệu xấu hoặc tài liệu có bản quyền xin hãy email cho chúng tôi.
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.