- July 7th, 2009
- 74 Comments
Ideally, users will fill the web form with necessary information and finish their job successfully. However, people often make mistakes. This is where web form validation comes into play. The goal of web form validation is to ensure that the user provided necessary and properly formatted information needed to successfully complete an operation. In this article we will go beyond the validation itself and explore different validation and error feedback techniques, methods and approaches.
User’s input can be validated on the server and on the client (web browser). Thus we have server-side and client-side validation. We’ll discuss pros and cons of each.
The exception is validation using Ajax. Ajax calls to the server can validate as you type and provide immediate feedback. Validation in this context refers to validating rules such as username availability. You can read more about validation with Ajax in this excellent tutorial1 on jQueryForDesigners.
This diagram shows differences between client-side and server-side validation and other techniques.
Rich, instant validation feedback is done on the client on TypePad
What to validate
There are several different types of validation you can perform: required fields, correct format and confirmation fields.
The first and most obvious information that should be validated is required information – information without which operation cannot be completed successfully. Thus, validation has to ensure that the user provided all the necessary details in the web form and it has to fail if at least one of the fields is not provided. Required fields should be clearly marked in order to inform users about what information has to be provided up front.
Required fields on Komodo Media blog comment form are marked with “required” help text.
A common way to mark required fields is with an asterisk (*). However, not all users know the meaning of an asterisk sign. Beginners or older users are very likely to have only a general idea of what an asterisk might mean. This is the reason why it is a good practice to either put a note on the top of the form that indicates that all fields marked with an asterisk are required or to use required field markers. In case that all fields are required there is no need to place asterisks or markers in the form. A simple message that all fields are required is enough.
Facebook doesn’t provide information about required fields. Users get information that all fields are required only after they press the “submit”-button.
Last year, we conducted an survey on Web form design5. According to that survey “designers tend to remove all unnecessary details and distractions which don’t help the user to complete the form”. More detailed analysis showed a trend of using very few mandatory fields – more than 50% of forms used at most 5 mandatory fields, while optional fields were often avoided. This can be useful to you when deciding on required fields.
Apart from ensuring that users provide necessary information, validation has to ensure that users provide information in the correct format. This applies to various cases such as email address, URL, dates, phone numbers and others. If the information is not in the correct format, users should be informed and correct format should be suggested. Probably the easiest way to validate the “correct” formatting is to use regular expressions.
Please notice that it is often a good idea to not impose a strict input pattern on the users; it’s better to actually permit users to enter text in a variety of formats and syntaxes, and make the application interpret it intelligently. The user just wants to get something done, not think about “correct” formats and complex UIs. Let the user type whatever he needs, and if it’s reasonable, make the software do the right thing with it. This design pattern is also often called forgiving format UI design pattern6.
Carbonmade sign-up form validates URL format, informs the user about the error and provides ways to correct it.
To learn more about regular expressions be sure to read Essential Guide To Regular Expressions: Tools and Tutorials8 or if you already know the basics: Crucial Concepts Behind Advanced Regular Expressions9. We’ll discuss some other format techniques later in the article.
When dealing with data that is important to the system, it is a good practice to let the users confirm their input using additional confirmation fields. This way users can be certain that they provided correct information. A typical case when confirmation field is used is for passwords, but it can be used in other cases like an email address.
Photobucket sign-up form required users to re-type password they previously entered in order to ensure it has been correctly entered.
A confirmation field should be placed next (or below) the target field. It has to clearly describe the purpose of the field such as “Confirm your password”. If two values do not match, the user should be informed. As an option, you can use a success indicator if values DO match.
The second part of our survey11 shows interesting information about confirmation fields. Email confirmation was mandatory in only 18% of sites, while password confirmation was mandatory in 72% of web sites. Surprisingly, large websites such as Facebook, LinkedIn, Stumbleupon and Twitter don’t require password confirmation.
If validation fails, the system should let the users know it by providing a clear and unambiguous message (usually one or two sentences) and ways to correct errors. Since users need to notice an error message immediately, it is a good practice to position it at the top of a web form, before all the other fields. This will also allow screen readers to easily access the message.
The message should be shown preferably in red since this is the color that people usually associate with errors and it should contain an appropriate icon in order to get more attention. Icon should be globally recognizable, such as a red circle with white cross. This will also help people with visual impairments identify the meaning of the message. In addition to this, users should be informed about which input fields need to be checked.
The Invoice Machine Sign-up form doesn’t provide error feedback. Error message is missing and input fields are colored with pastel red that is not easy to spot.
Apart from the error message and a list of invalid fields, the system should clearly mark fields that are invalid. This can be done in one of the following ways (or any combination of them):
- By providing red inline messages or markers next to every invalid field
- By changing the background color or border color of invalid fields (to red)
- By changing the color of field labels
- By providing error tips (balloons) next to each field
If you provide error tips or help, be short and informative. For example, if date is in an incorrect, format provide users with details on how to format it properly: “The date should be in the dd-mm-yyyy-format”. It is sometimes also a good idea to have these hints as the initial value of your input fields. Thus, the user will first read the hint inside the input box and when he/she will start typing the data, the hint will disappear.
Validation upon submit
The “classic” way to perform validation is when the user submits his data via the “submit”-button. The validation is executed and if any errors are found, feedback is returned and displayed to the user. This way users will be able to fill the form without any interruptions. But, that could be a disadvantage as well. Users will be able to fix the errors only after they try to submit the form and get the response back from the server. This technique is typical for server-side validation, but can also be done on the client side.
Feedback on Ballpark sign-up form occurs upon submit. It shows an obvious error message with incorrect fields at the top of the form and marks each incorrect field with a tip.
Real-time validation (or instant validation)
In contrast to the previous technique, real-time-validation alerts users while they are filling in the form. That doesn’t necessarily mean that the validation is performed on every single key press but rather when a field loses focus. This way users will get immediate feedback about their input, e.g. if a username is available or if a date is in the correct format. Obviously, instant validation occurs during typing in an input field or after the input field loses focus. Usually, it is complemented with a text message, tip or a status icon.
Yahoo registration form implements password strength meter that gives feedback as you type in the letters.
Instant validation should be implemented carefully and in appropriate cases because it might be distracting if overused or misused.
Sign-up form on TypePad not just provides instant validation feedback that informs users of different validation errors – it also indicates successfully entered information.
What to avoid?
There are two things you should really try to avoid when designing form validation. First, single error pages are bad practice. Singe error page means that users are redirected from the Web form they filled to a page that shows some feedback. In this case, users are forced to browse back in order to fix errors. When they browse back they will have to memorize the information you provided in the error message. The same applies to feedback messages in popup windows. Not only are popups annoying, but once they are closed all the feedback is lost.
An interesting finding in the second part of SM survey16 is that “30% of the forms displayed only an error-message at the top of the form (no input fields were highlighted)” while “29% had highlighted input fields with corresponding messages next to the input field (no error-messages were provided at the top of the page)”. Only 25% used both error-messages and input fields.
Better safe than sorry
Apart from the pure validation, there are several techniques that can help users make fewer mistakes. Although not all of these techniques can be considered validation, they do help by guiding users and preventing them from making mistakes.
WishListr provides useful help information on the right side of each field.
Help indicators (tooltips)
In contrast to help hints, tooltips initially hide information and make it visible “on demand”. They are usually triggered by an icon with a question mark. Help information is shown by hovering over the help icon or clicking on it. Once the mouse is moved away from the icon, the tooltip disappears. Help indicators can reduce clutter, especially if help text is too long.
Sign-up form on TicketTrunk contains obvious help indicators that provide help information on hover.
Similar to the previous case, dynamic tips are initially not visible to users. Once the user enters a particular input field, related tip is shown. This way tips are emphasized and clutter in the form is reduced. Tips should be shown in such a way that they don’t cover other information on the form. They are usually shown next to input fields, but you should always try to place them on the right side of the fields since that is less distracting.
Digg registration form has discrete dynamic tips that show help information related to the field that has the focus.
Masking and reformatting user’s input
Apart from validating user’s input and assisting users, web applications can also take part in providing correct data by formatting user’s input. This can be done by masking input fields in order to force users to enter information in an appropriate format. Mask is an expression that controls what users can enter in an input field. Masking can be implemented easily with one of the following plugins:
In some cases users might fill partially correct information or correct information but in different format. In those cases web application can provide a mechanism to correct and rewrite the user’s input. Some of the possible scenarios when you might consider rewriting user’s input are:
- if, for instance, a user enters URL without “http://” prefix, the system can just add this string to the beginning of URL.
- if a user provides data in the dd-mm-yyyy-format, but the required format is yyyy-mm-dd, the system can rewrite the date so it is well-formed
- if a user provides credit card number without dashes, the system can add dashes to appropriate positions in the credit card number
Tumblr provides a sort of masking for URL.
These ideas are just some of the cases when this technique can be used. However, auto-formatting should be used carefully and – if not used properly – can be confusing to users. Also, not all user’s input is predictable. If, for example, user enters “www.smashingmagazine” and omits the extension, the system can’t assume that the extension is “.com”, but should rather raise a validation error.
In this context it’s again worth mentioning the “forgiving format” design pattern. Instead of restricting user’s input to a specific format you can allow users to provide various formats and let the system parse it. In many cases this would require a lot of server processing; back-end would be responsible for parsing the input, extracting information and converting it to appropriate formats for further processing.
Google Calendar has a very clever implementation of this technique with one-field for adding events. Users can enter information in various formats (even use “tomorrow” instead of date); the system parses it and stores it as a new event. If user provides information that can’t be parsed, system assumes that this information is event title and redirects the user to a longer version of the form with filled event name. This way Google completely omitted validation.
According to our survey. 67% of sites use help text and tips, 10% of which use dynamic tips. Surprisingly, only 26% of tips are positioned on the right side of the fields, while in other cases tips are positioned above, below and even on the left side of input fields.
Are you human?
Web form validation wouldn’t be complete without mentioning Captcha. Captcha is a significant part of validation as it is responsible for finding out if the user of a system is a human or a bot. In its simplest form, captcha consists of an image showing text, numbers or an expression and a field that expects content of the image as input. The earliest captcha generated images with numbers (e.g. “8356″) and that number was expected to be entered by the user. If correct number wasn’t entered (or not entered at all), the form couldn’t be submitted. In fact, today most spam bots are able to recognize the text embedded in a simple captcha-image, so it’s a good idea to pose some question that only humans could answer correctly, e.g. “What color does the Sun have?” with correct answer “yellow” in all its variations (“YELLOW”, “yellow”, “Yellow” etc.).
You may also want to consider the technique called Honeypot Captcha28 where the idea is to create hidden form elements and check on the server side that they remain blank. Another option is to create a form field with a label that says, “Leave this field blank” and then is marked as a required field (thank you, Shawn McCool).
Simple captcha requires an answer to a semantic question.
The kind of captcha presented above caused a major problem in accessibility. Blind, visually impaired or dyslexic users have difficulties or are even impossible to complete the web form with Captchas. As the Web evolved, so did captchas and today there are implementations like ReCaptcha29 that have audio support for users with disabilities.
Captchas can show hardly recognizable words. Can you easily read the word on the left?
Still most users hate captchas (and there is a good reason for hating them!). Of course, people just don’t like filling in forms. If they can’t do it fast and effortlessly, there is a high probability that they won’t do it at all. This is where a captcha doesn’t help at all: it can take too much time for users to read (if text is messy) which happens oft in practice. Remember, Captcha helps site owners, not their users. Therefore it’s always a good idea to avoid using Captchas if you can avoid them. To read more about Captchas and accessibility, read Inaccessibility of CAPTCHA31.
Captcha on Digg registration form has audio support. If unable to read, users will be able to hear the letters shown in the image.
Here are some of the frameworks, plugins and tutorials that might help you easily implement validation in your forms.
A validation framework that enables rich client-side validation.
- PhatFusion Validate37
An attempt to standardize form markup (xhtml) and CSS. It can help you style error messages, help text, indicators and so on.
- jQuery Validation plugin39
One of the most popular validation plugins. As expected from jQuery plugin, it enables validation in one line of code, but you can also customise it. It has only 14 kb and is compatible with jQuery 1.3.2.
Another jQuery plugin that lets you implement validation easily. Not only that it performs validation but also has the support for live tips. It is still in development phase but is worth checking.
Provides easy validation and attractive error messages.
- jQuery Form Validator42
Another great jQuery validation plugin that performs live validation. It is fully customisable and supports localisation as well.
- Validation Hints for your form44
- Screencast: Quick PHP Form Validation with PEAR45
A nice example of how you can validate PHP forms using PEAR framework.
- PHP Contact Form with jQuery Validation46
- How to Validate Forms on both sides using PHP and jQuery47
Shows how to implement both client-side and server-side validation using PHP.
- Adding Form Validation to WordPress Comments using jQuery48
An interesting tutorial for all WordPress users.
You saw different methods and techniques that you can use to implement validation in your forms. Although there are many possibilities, you should carefully plan validation for each project. Not all techniques provide a solution for everything. Some of them are very helpful and easy to implement, but some lack usability and simplicity. If you are new to web form design here is a short list of what to consider in Web form validation design). That might be enough for you to start.
Rules of thumbs in web form validation design
- Never omit server-side validation.
- Don’t provide confusing validation feedback. It should clearly communicate the errors and ways to fix them.
- Don’t let users think about what information is required, always clearly mark required fields.
- Never provide validation feedback on a single page or in a popup alert.
- Don’t use dynamic effects as compensation for a badly designed form. Fancy effects won’t hide a poorly designed web form.
- If you use Captcha, don’t forget to provide audio support and enable users to “reload” the Captcha.
- Don’t forget to inform users when the form was completed successfully. It is as important as a good validation feedback.
- 1 http://jqueryfordesigners.com/using-ajax-to-validate-forms/
- 2 https://www.typepad.com/secure/services/register?acct_level=pro
- 3 http://www.komodomedia.com/blog/2009/06/social-network-icon-pack/
- 4 http://www.facebook.com
- 5 http://www.smashingmagazine.com/2008/07/04/web-form-design-patterns-sign-up-forms/
- 6 http://designinginterfaces.com/Forgiving_Format
- 7 http://www.carbonmade.com/signup
- 8 http://www.smashingmagazine.com/2009/06/01/essential-guide-to-regular-expressions-tools-tutorials-and-resources/
- 9 http://www.smashingmagazine.com/2009/05/06/introduction-to-advanced-regular-expressions/
- 10 http://register.photobucket.com/?ref=joinus
- 11 http://www.smashingmagazine.com/2008/07/08/web-form-design-patterns-sign-up-forms-part-2/
- 12 http://invoicemachine.com/signup
- 13 https://www.getballpark.com/public/signup?plan=5
- 14 https://edit.yahoo.com/registration
- 15 https://www.typepad.com/secure/services/register?acct_level=pro
- 16 http://www.smashingmagazine.com/2008/07/08/web-form-design-patterns-sign-up-forms-part-2/
- 17 http://www.wishlistr.com/signup/
- 18 http://tickettrunk.com/event/add
- 19 http://digg.com/register/
- 20 http://www.meiocodigo.com/projects/meiomask/
- 21 http://zendold.lojcomm.com.br/imask/
- 22 http://typecast.arapehlivanian.com/index.html
- 23 http://digitalbush.com/projects/masked-input-plugin/
- 24 http://typecast.arapehlivanian.com/index.html
- 25 http://typecast.arapehlivanian.com/index.html
- 26 http://www.tumblr.com/register
- 27 http://www.google.com/calendar/
- 28 http://haacked.com/archive/2007/09/11/honeypot-captcha.aspx
- 29 http://recaptcha.net/
- 30 https://edit.yahoo.com/registration
- 31 http://www.w3.org/TR/turingtest/
- 32 http://digg.com/register/
- 33 http://www.livevalidation.com/
- 34 http://www.livevalidation.com/examples
- 35 http://www.drlongghost.com/validanguage.php
- 37 http://www.phatfusion.net/validate/
- 38 http://www.sprawsm.com/uni-form/
- 39 http://bassistance.de/jquery-plugins/jquery-plugin-validation/
- 40 http://frontendbook.com/projects/jform/
- 42 http://www.position-absolute.com/articles/jquery-form-validator-because-form-validation-is-a-mess/
- 43 http://www.askthecssguy.com/2007/03/form_field_hints_with_css_and.html
- 44 http://www.askthecssguy.com/2007/05/validation_hints_for_your_form_1.html
- 45 http://www.havocinspired.co.uk/tutorial/screencast-quick-php-form-validation-with-pear/#comments
- 46 http://www.raymondselda.com/php-contact-form-with-jquery-validation/
- 47 http://yensdesign.com/2009/01/how-validate-forms-both-sides-using-php-jquery/
- 48 http://net.tutsplus.com/tutorials/wordpress/adding-form-validation-to-wordpress-comments-using-jquery/