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

Similar Reads

Empty Field Validation

This is used to check if user has added any data in the required input field. Here, empty() is used to check if a variable is empty or not....

String Validation

This is used to check if user has added valid string in the required input field. Here, preg_match() is used for pattern matching....

Number Validation

This is used to check if user has added only numbers in the required input field....

Email Validation

This is used to check if user has added a valid email in the required input field....

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....

URL Validation

This is used to check if user has added a valid URL in the required input field....

Button Click Validation

This is used to check if user has pressed the required button. Here, isset() is used to check if a variable is declared and is not NULL....