URL Validation
This is used to check if user has added a valid URL in the required input field.
$url = $_POST["url"];
// This pattern is standard for URL validation
$pattern = "/\b(?:(?:https?|ftp):\/\/|www\.)[-a-z0-9+&@#\/%?=~_|!:,.;]*[-a-z0-9+&@#\/%=~_|]/i"
// To check that URL address syntax is valid
if (!preg_match($pattern, $url)) {
$errorMsg = "You entered an INVALID URL";
}else{
echo $url;
}
PHP Form Validation
Form validation is a crucial step that needs to be completed before submitting data to the database. This process is performed to prevent any errors or faulty data from being inserted into the database. The HTML form includes various input fields such as email, text, checkbox, radio button, etc. These input fields must be validated to ensure that the user enters only the intended values and not incorrect ones.
Table of Content
- Empty Field Validation
- String Validation
- Number Validation
- Email Validation
- String Length Validation
- URL Validation
- Button Click Validation