How to apply validations in PHP?
How to apply validations in PHP???
|
Hi! Today we are going to review a very important part of the development process of a web application. The validation of users input. This is one the trickiest parts of any application at all. Why is that? Because the developer doesn't control it. You can write the best algorithm in the world, but still if it includes user input there is a place for mistakes. Even if we put some coplicated logic to prevent the input of wrong symbols, check the consistence of the data and do whatever possible to make sure that it is all OK, there is still possibility that the users enter the wrong number. Though all said, we must try to prevent the most of human errors and the best way to do this is by using Regular Expressions.
Basicly Regular Expressions are used for string matches. They are based on search and pattern matching strings in text. A lot of books are written about them, there are even some programming languages designed especially for Regular Expressions. But today we are just going to take a brief look at how regular expressions can help us with user input. First of all I suggest that you get familiar with some basic concepts of the language. Now let's get to work. I'll present some of the most common problems with user input. I'm pretty sure that you met most of them if not all. We are going to create a registration form with required input fields. They are as follows: - Full Name - Address - Passport - Phone - Zip code - Date - Username - Password ----------------------------------- http://www.bestwebsol.com |
thanks for the information but can u please let us know how to apply validations in php ?
|
hello.........
very nice post. thanks for the info. regards, cyrusholiday http://www.cyrusholiday.info |
great post such a useful information thanx for sharing.
and keep sharing. |
Are you asking about PHP form validation?
|
you can use 3rd party validation classes.. or you can read more here, stackoverflow dot com/questions/737385/easiest-form-validation-library-for-php#answer
|
There are two ways to use regular expressions in php. One is the true PHP style in which case we have to use ereg() function and the other is to use Perl style syntax for our validations. In this case we have to use preg_match() function. In this tutorial we will use preg_match() because it is faster in most cases and also supports the most common regular expression syntax. It also gives us more capabilities, that we can use.
|
we can use JavaScript for validation.it has a embedded language with php.......
|
jimimartin52...
Its very useful to know about the concept..thanq |
For validating (I assume you are talking about form validation, correct me if I am wrong), best way is to use JavaScript Validation. You can use jQuery or any JS library you are using. For serverside validation, you have to build logic by yourself.
|
you will use if statements for validation
for example if(strln($password) < 8) { echo "Your Password must be 8 char. at least"; } and so on, and also you will use regular expressions a lot |
Form Validation is important particularly if you are going to save the data in a database
|
All times are GMT -7. The time now is 03:11 AM. |
Powered by vBulletin Copyright © 2020 vBulletin Solutions, Inc.