Start C validating tutorial

C validating tutorial

If your web browser supports HTML5, it will not allow you to submit the form without entering text into the input field.

I will test each example on Linux (g -4.6.1 and clang), Mac OSX (g -4.6.1 and clang) and finally Windows (Visual C 2010 and g -4.6.1).

If you find that one of the examples presented here works with a different combination of compiler/OS, please drop me a note and I will include this in my post.

Let's start with a simple example, suppose we are trying to validate an integer inputed by the user.

C will accept this kind of numerical input: 0012, 12, 0012 or the negative -0012, -12, -0012.

Any leading zeros will be ignored and for positive numbers we can safely use, or not, the plus sign.

First we will need a regular expression that will match numbers in the above format.

In addition to providing instructions, validate user input to help users avoid mistakes.