String Length Validation
This is used to check if the length of the string is in valid range. Here, strlen() is used to find the length of the string.
$phoneNo = $_POST["phoneNo"];
// To check that length of Phone Number length should not be less and greator than 10
if (strlen($phoneNo) != 10) {
$errorMsg = "Please provide a phone number of 10 digits!!";
}else{
echo $phoneNo;
}
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