data validation data validation in computer science, data validation is the process of ensuring data has undergone data cleansing to ensure they have data quality, that is, that they are both correct and useful. it uses routines, often called "validation rules", "validation constraints", or "check routines", that check for correctness, meaningfulness, and security of data that are input to the system. the rules may be implemented through the automated facilities of a data dictionary, or by the inclusion of explicit application program validation logic of the computer and its application. this is distinct from formal verification, which attempts to prove or disprove the correctness of algorithms for implementing a specification or property. overview data validation is intended to provide certain well-defined guarantees for fitness and consistency of data in an application or automated system. data validation rules can be defined and designed using various methodologies, and be deployed in various contexts. their implementation can use declarative data integrity rules, or procedure-based business rules. the guarantees of data validation do not necessarily include accuracy, and it is possible for data entry errors such as misspellings to be accepted as valid. other clerical and/or computer controls may be applied to reduce inaccuracy within a system. different kinds in evaluating the basics of data validation, generalizations can be made regarding the different kinds of validation according to their scope, complexity, and purpose. for example: data type validation; range and constraint validation; code and cross-reference validation; structured validation; and consistency validation data-type check data type validation is customarily carried out on one or more simple data fields. the simplest kind of data type validation verifies that the individual characters provided through user input are consistent with the expected characters of one or more known primitive data types as defined in a programming language or data storage and retrieval mechanism. for example, an integer field may require input to use only characters 0 through 9. simple range and constraint check simple range and constraint validation may examine input for consistency with a minimum/maximum range, or consistency with a test for evaluating a sequence of characters, such as one or more tests against regular expressions. for example, a counter value may be required to be a non-negative integer, and a password may be required to meet a minimum length and contain characters from multiple categories. code and cross-reference check code and cross-reference validation includes operations to verify that data is consistent with one or more possibly-external rules, requirements, or collections relevant to a particular organization, context or set of underlying assumptions. these additional validity constraints may involve cross-referencing supplied data with a known look-up table or directory information service such as ldap. for example, a user-provided country code might be required to identify a current geopolitical region. structured check structured validation allows for the combination of other kinds of validation, along with more complex processing. such complex processing may include the testing of conditional constraints for an entire complex data object or set of process operations within a system. consistency check consistency validation ensures that data is logical. for example, the delivery date of an order can be prohibited from preceding its shipment date. example multiple kinds of data validation are relevant to 10-digit pre-2007 isbns (the 2005 edition of iso 2108 required isbns to have 13 digits from 2007 onwards). size. a pre-2007 isbn must consist of 10 digits, with optional hyphens or spaces separating its four parts. format checks. each of the first 9 digits must be 0 through 9, and the 10th must be either 0 through 9 or an x. check digit. to detect transcription errors in which digits have been altered or transposed, the last digit of a pre-2007 isbn must match the result of a mathematical formula incorporating the other 9 digits (isbn-10 check digits). validation types allowed character checks checks to ascertain that only expected characters are present in a field. for example a numeric field may only allow the digits 0–9, the decimal point and perhaps a minus sign or commas. a text field such as a personal name might disallow characters used for markup. an e-mail address might require at least one @ sign and various other structural details. regular expressions can be effective ways to implement such checks. batch totals checks for missing records. numerical fields may be added together for all records in a batch. the batch total is entered and the computer checks that the total is correct, e.g., add the 'total cost' field of a number of transactions together. cardinality check checks that record has a valid number of related records. for example, if a contact record is classified as "customer" then it must have at least one associated order (cardinality > 0). this type of rule can be complicated by additional conditions. for example, if a contact record in a payroll database is classified as "former employee" then it must not have any associated salary payments after the separation date (cardinality = 0). check digits used for numerical data. to support error detection, an extra digit is added to a number which is calculated from the other digits. consistency checks checks fields to ensure data in these fields correspond, e.g., if expiration date is in the past then status is not "active". cross-system consistency checks compares data in different systems to ensure it is consistent. systems may represent the same data differently, in which case comparison requires transformation (e.g., one system may store customer name in a single name field as 'doe, john q', while another uses first_name 'john' and last_name 'doe' and middle_name 'quality'). data type checks checks input conformance with typed data. for example, an input box accepting numeric data may reject the letter 'o'. file existence check checks that a file with a specified name exists. this check is essential for programs that use file handling. format check checks that the data is in a specified format (template), e.g., dates have to be in the format yyyy-mm-dd. regular expressions may be used for this kind of validation. presence check checks that data is present, e.g., customers may be required to have an email address. range check checks that the data is within a specified range of values, e.g., a probability must be between 0 and 1. referential integrity values in two relational database tables can be linked through foreign key and primary key. if values in the foreign key field are not constrained by internal mechanisms, then they should be validated to ensure that the referencing table always refers to a row in the referenced table. spelling and grammar check looks for spelling and grammatical errors. uniqueness check checks that each value is unique. this can be applied to several fields (i.e. address, first name, last name). table look up check a table look up check compares data to a collection of allowed values. post-validation actions enforcement action enforcement action typically rejects the data entry request and requires the input actor to make a change that brings the data into compliance. this is most suitable for interactive use, where a real person is sitting on the computer and making entry. it also works well for batch upload, where a file input may be rejected and a set of messages sent back to the input source for why the data is rejected. another form of enforcement action involves automatically changing the data and saving a conformant version instead of the original version. this is most suitable for cosmetic change. for example, converting an entry to a entry does not need user input. an inappropriate use of automatic enforcement would be in situations where the enforcement leads to loss of business information. for example, saving a truncated comment if the length is longer than expected. this is not typically a good thing since it may result in loss of significant data. advisory action advisory actions typically allow data to be entered unchanged but sends a message to the source actor indicating those validation issues that were encountered. this is most suitable for non-interactive system, for systems where the change is not business critical, for cleansing steps of existing data and for verification steps of an entry process. verification action verification actions are special cases of advisory actions. in this case, the source actor is asked to verify that this data is what they would really want to enter, in the light of a suggestion to the contrary. here, the check step suggests an alternative (e.g., a check of a mailing address returns a different way of formatting that address or suggests a different address altogether). you would want in this case, to give the user the option of accepting the recommendation or keeping their version. this is not a strict validation process, by design and is useful for capturing addresses to a new location or to a location that is not yet supported by the validation databases. log of validation even in cases where data validation did not find any issues, providing a log of validations that were conducted and their results is important. this is helpful to identify any missing data validation checks in light of data issues and in improving the validation. validation and security failures or omissions in data validation can lead to data corruption or a security vulnerability. data validation checks that data are fit for purpose, valid, sensible, reasonable and secure before they are processed.