validation : Java Glossary

validation
Checking that data is correct and cross-consistent before allowing it into your databases. Unfortunately Java has no serious built-in data validation classes, though in Swing you have some roll-your-own validation with the InputVerifier interface, and numeric validation with DecimalFormat and date validation with SimpleDateFormat. JFormatttedTextField is a roll your own Component for entering data such as serial numbers with letters in some slots and numbers in others.

There are no methods validate addresses, phone numbers, postal codes, zip codes, provinces, states, countries, spelling, lack of accented characters, encodability, character classes or presence of separator chars at fixed positions…

It is much better to spend extra effort to keep bad data out, than to try to detect and remove it later. Never postpone data validation until later! One difficulty with writing data validation classes for things like Zip codes, postal codes, phone numbers etc. is they are based on tables that need to be frequently refreshed. It also best to warn the user of any data validation error as soon as possible, e.g. on the very keystroke or field level. Unfortunately web-based applications are dreadful in this regard, only warning the user after an entire screenful of data have been keyed. Data validation rules should be centralised so that all data are always validated the same way. Unfortunately, Java has no declarative mechanism to enforce all incoming data to be uniformly validated, e.g. design by contract. You must explicitly code it.

Learning More

Oracle’s Javadoc on InputVerifiers class : available:
Oracle’s Javadoc on JFormatttedTextField class : available:

CMP homejump to top You can get the freshest copy of this page from: or possibly from your local J: drive (Java virtual drive/mindprod.com website mirror)
http://mindprod.com/jgloss/validation.html J:\mindprod\jgloss\validation.html
logo
Please email your , letters to the editor, errors, omissions, typos, formatting errors, ambiguities, unclear wording, broken/redirected link reports, suggestions to improve this page or comments to Roedy Green : feedback email. If you want your message, your name or email kept confidential, not considered for public posting, please explicitly specify that. Unless you state otherwise, I will treat your message as a letter to the editor that I may or may not publish in the feedback section. After that, it will be too late to retract it. If you disagree with something I said, please quote it and cite the web page where you found it, tell me why you think it is wrong, and, if possible, provide some supporting evidence. Threatening to kill me or spouting obscenities has yet to persuade me to change my mind.
mindprod.com IP:[65.110.21.43]
view BlogYour face IP:[38.107.179.214]
You are visitor number 15,404.