tailieunhanh - Validating Strings

Như đã đề cập trước đó trong bài học này, khi xác nhận các loại dữ liệu (tên, số điện thoại, địa chỉ email, vv) tốt nhất để phá vỡ quá trình vào chức năng chuyên ngành hoặc thói quen xác nhận. Chúng tôi sẽ bắt đầu quá trình trong tập thể dục này. Loại đầu tiên của mẫu dữ liệu của chúng tôi yêu cầu là tên của người dùng. Đối với hình thức của chúng tôi, các dữ liệu nhập vào phải đáp ứng hai yêu cầu. | Validating Strings As mentioned earlier in this lesson when validating different types of data names phone numbers email addresses and so on it s best to break the process into specialized functions or validation routines. We will begin that process in this exercise. The first type of data our form asks for is the user s name. For our form the data entered must meet two requirements Length. The name must be at least two characters long. Type. Text must be used a number cannot be accepted as a valid name. NOTE We could define other validation points such as a maximum length or even that the name begin with a D but the ones we have chosen are sufficient for our purposes. In this exercise we ll create a function for validating the name entered into our project s registration form. 1. Open . We ll build 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 validateName 5. 6. if 2 isNaN false 7. 8. Please enter a valid name. 9. 10. color 0x990000 11. 12. 13. 14. 15. When called this function checks the data entered in the name_ti instance for two conditions length and type the validation points we defined at the beginning of this exercise . The conditional statement here says that if the name_ti instance contains fewer than two characters or is a number which would be considered an error the string Please enter a valid name should be pushed into the errors array. In addition we use the setStyle method to change the color of text in the name_ti instance to red to make the location of the error a little more noticeable. Although we ve used the length property in other scripts some of this syntax is new and thus requires explanation. One of the validation points we ve defined for the name_ti instance is that a number entered into it would be considered an .

crossorigin="anonymous">
Đã 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.