In accordance with the concepts deployed in the section that you just read, it’s necessary to create some simple examples that show how to use the validation helper class in concrete cases. With that thought in mind, below I included two approachable code samples that use the helper for validating first an integer, and then a float number. Here are the examples in question: $validator = new ValidatorHelper();
// example on validating an integer value if ($validator->validate_int(10.2, 1, 100) === FALSE) { echo 'Input value is not a valid integer.'; } else { echo 'Input value is a valid integer.'; } /* displays the following Input value is not a valid integer. */
// example on validating a float value if ($validator->validate_float(1234.5) === FALSE) { echo 'Input value is not a valid float number.'; } else { echo 'Input value is a valid float number.'; } /* displays the following Input value is a valid float number. */ Definitely, understanding the examples shown above is a pretty straightforward process. The “validate_int()” and “validate_float()” methods of the helper are called after creating an instance of it. Also, in this particular case I fed these methods with rather trivial values to make the examples easier to grasp, but logically more complex parameters can be used. So far, so good, right? Now that you've grasped how to use the previous validation helper class for checking integer and float numbers, it’s time to continue evaluating its functionality. As you’ll recall, the class also has some other methods, which can be used for validating IP and email addresses, alphabetic and alphanumeric values and finally URLs. So, in the last segment of this tutorial I’m going to demonstrate how to validate those specific types of data. So click on the link shown below and read the following lines.
blog comments powered by Disqus |
|
|
|
|
|
|
|