• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

Chapter 21. Using JavaScript to Create S... > Client-Side Form Validation

Client-Side Form Validation

Form validation is one of the most common JavaScripting tasks. Many Web applications need to gather input from users. Traditionally, this data is entered in the browser and then transmitted to the server. The server checks the validity of the data and either stores the data on the server or sends back a message requesting additional information or asking the user to enter valid data. This slows your Web server and creates unnecessary Web traffic. With just a few lines of code, you can validate much of this data on the client's machine and send it to the server only after it is complete. Of course, you still need to completely validate data on the server as well, because people still use browsers that either don't support JavaScript or have it turned off.

This chapter discusses ways of using JavaScript to make your XHTML forms smarter. First, a few examples give you some ideas on how to use JavaScript to prefill, validate, and format XHTML form elements. After that, the discussion focuses on how you can make sure a credit card number is well formed—obviously, it's not possible to truly validate a credit card number at the client, but it is possible to determine whether the number is a valid format. Finally, this chapter reviews a couple of collections of JavaScript form validation scripts that are freely available on the Web. These collections should get you well on your way to adding form validation to your Web pages.


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


  
  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint