Loading [MathJax]/jax/output/HTML-CSS/fonts/TeX/fontdata.js

Text Validation

Sometimes when dealing with text input fields, validating only the length of the string or if it is there or not is simply not enough. Most of the times we want to ensure that the user is giving us a data on a specific predefined format. That way we can define a pattern of the expected string. 

This pattern is only an abstracted blueprint of how the data from the user should be like in order to be accepted. 

Think a bit about the e-mail validation forms. There are many email type accounts. Let's look at some of them as examples: 

kostasdiakogiannis23@gmail.com

johndoe@hotmail.com

freddy.kruger@gmx.net

Now although at a first glance these emails seem to be completely different, if you look closely you may find that all of them are comprised from some parts. The first part that can contain possibly letters, numbers and/or special characters, that is always followed by a literal '@', then the second part which is also comprised of a unknown number of letters, numbers and special characters and ends with a literal dot (.) followed by the address (which is comprised by letters and most of the times the length is between two and four).

In order to accept multiple addresses, that match all these different combinations you should write hundreds of lines of code to predict all the outcomes.