Validating Numbers

Validating số Validating số không phải là nhiều khác nhau từ các chuỗi xác nhận, mà chúng tôi đã thảo luận. Trong bài tập này, chúng tôi sẽ tạo một chức năng xác nhận cuối cùng để xác nhận các dữ liệu nhập vào zip_ti dụ. Để có một năm chữ số hợp lệ zip code, dữ liệu nhập vào phải đáp ứng hai yêu cầu sau đây | Validating Numbers Validating numbers is not much different from validating strings which we ve already discussed. In this exercise we ll create one last validation function to validate the data entered into the zip_ti instance. To be a valid five-digit zip code the entered data must meet the following two requirements Length. The data must include exactly five characters. Type. The data must contain numbers text is invalid. TIP When validating numbers you may need to call for the number entered to be more or less in value than another number which by now you should be able to do easily 1. Open . We will continue building on the project from the last exercise. 2. With the Actions panel open select Frame 1 on the Actions layer and add the following function definition at the end of the current script 3. 4. function validateZip 5. 6. if 5 isNaN true 7. 8. Please enter a valid zip. 9. 10. color 0x990000 11. 12. 13. 14. 15. When called this function checks that the data entered into the zip_ti instance meets two conditions regarding length and type the validation points we defined at the beginning of this exercise. The conditional statement here states that if the zip_ti instance does not contain five characters or if it consists of text rather than numbers the text in the zip_ti instance should be styled as red and the following text string should be pushed into the errors array Please enter a valid zip. NOTE If you need to refresh your understanding of isNaN review the information in the Validating Strings exercise earlier in this lesson. 3. Add the following function call just below the validateState function call in the validateForm function 4. 5. validateZip 6. This is a call to the function we just defined. Placing this function call here adds zip code validation capability to the main validateForm function. This function call is placed just above the statement that checks the length of the .

Bấm vào đây để xem trước nội dung
TÀI LIỆU MỚI ĐĂNG
1    96    2    03-07-2024
Đã 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.