In the code below, we have passed two argument values to this function.

validating data php-50validating data php-70

Imagine that you’ve got a user form that accepts adding comments on a page.

You have fields for someone to add a comment that includes their name, email address, comment, and a hidden field of the page ID they’re commenting on.

In the example above, the password is valid if it is at least 6 characters long and if it contains at least one capital letter and at least one number. If the user enters the phone number in an invalid format, an error message is shown.

In the example above, a phone number is valid only if it is 10 digits long. If the user enters the postal code in an invalid format, an error message is shown.

Validating means verifying the data coming into your script is the type of data you want, is in the correct format, and is the right length. Depending on what your script does, it can lead to your site going down, displaying bad information, giving the bad guys access to getting information from users, and much more.

The first step in validating your data is knowing what data should come in.

Since this is a beginner’s post on basic validation and sanitization, you’ll want to learn more about keeping your site secure.

As Master Yoda says, “Much to learn, you still have.” Validating user input is the first and one of the most important steps to securing your site.

Very first we have to create a form in html setting action “#” and method “POST” with some fields, when a user clicks on submit button all the data starts travel in URL but it will be hidden, as we set method = “POST”.

In this day and age, when the internet is vast and extends sooo far, there are annoying folks who want to be malicious.

‘ function checks if the pattern specified in the regular expression exists in the second argument value, which is a string value.