• 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

One of the most common tasks for JavaScripting is to do form validation. 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. Not only does this slow down your Web server, but it creates unnecessary Web traffic as well. 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 they have it turned off.

This chapter discusses ways of using JavaScript to make your HTML forms smarter. First, a few examples give you some ideas on how to use JavaScript to prefill, validate, and format HTML form elements. After that, the discussion focuses on how you can make sure a credit card number is well formed— obviously, it is 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 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