TAILIEUCHUNG - Học JavaScript qua ví dụ part 87

Mẫu xác thực với biểu hiện thường xuyên Khi bạn điền vào một mẫu trên web, bạn thường hỏi tên, địa chỉ số điện thoại, (một menu popup của tất cả các tiểu bang thường được cung cấp), và sau đó tất cả các loại thông tin thẻ tín dụng. Đôi khi nó có bốn hoặc năm cố gắng để có được nó ngay bởi vì bạn đã không hoàn thành biểu mẫu chính xác cách bạn được yêu cầu. | Form Validation with Regular Expressions 765 Figure Subpatterns are used in string replacement. Form Validation with Regular Expressions When you fill out a form on the Web you are typically asked for your name phone number address a popup menu of all the states is usually provided and then all sorts of credit card information. Sometimes it takes four or five tries to get it right because you didn t complete the form exactly the way you were asked. A message will appear and you won t be allowed to submit the form until you get it right. Behind the scenes a JavaScript program is validating the form. Checking for Empty Fields There s a form waiting to be filled out. Some of the fields are optional and some are mandatory. The question is this Did the user fill in the mandatory fields If he or she didn t the form can t be processed properly. Checking for empty or null fields is one of the first things you might want to do. EXAMPLE html head title Checking for Empty Fields title script type text javascript 1 function validate_text form1 2 if null alert You must enter your name. return false 3 if null alert You must enter your phone. return false Continues From the Library of 766 Chapter 17 Regular Expressions and Pattern Matching EXAMPLE continued else 4 return true script head body hr h2 Checking for Empty fields h2 5 form name formtest action cgi-bin method get onSubmit return validate_text formtest Please enter your name br 6 input type text size 50 name user_name p Please enter your phone number br 7 input type text size 30 name user_phone p p input type submit value Send input type reset value Clear p form body html EXPLANATION 1 A user-defined function called -validate_text is defined. It takes one parameter a reference to a form. 2 If the value in the first text field is an empty string represents a string with no .

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.