SiteExperts.com Logo Home | Community | Developer's Paradise | Jobs
User Groups | Site Tools | Site Information | Search

Inside Technique : Custom Input Validation : Conclusion

Using the TextRange object with the input controls provides complete control over the user's input. You can use the TextRange object for simple on-the-fly input validation and even formatting. We hope this article has introduced you to the TextRange object and a few techniques you can use to better control and validate user's input. You can find more information about the TextRange object in Chapter 14 of the book Inside Dynamic HTML or in Internet Explorer 4.0's SDK.

Cross-Browser Considerations

While Netscape Navigator 4.0 does support keyboard events on the input controls, there is no way (that we know of) in Netscape Navigator to build the demonstrated on-the-fly validation and formatting. While you can test a character as it is typed, there is no way to determine the location of the current insertion point and selection. Furthermore, any changes to the value of the text box causes the selection to be reset.

If cross-browser testing is required, we recommend you also write a function that tests the value on the onchange event. This event occurs after the user types a value and leaves the text box. At this time, you can test if the entered value fits the specified format. If it fails, alert the user and ask them to reenter it. While not as powerful and interactive as the approach presented by this article, the onchange event works in all Javascript aware browsers.

Discuss and Rate this Article