PHP Validation Example

please click here for more wordpress cource

Sure! Here’s an example of PHP validation code for a form field:

if(isset($_POST['email'])) {
  $email = $_POST['email'];

  // Remove illegal characters from email
  $email = filter_var($email, FILTER_SANITIZE_EMAIL);

  // Validate email
  if(filter_var($email, FILTER_VALIDATE_EMAIL)) {
    // Email is valid
  } else {
    // Email is not valid
    echo "Invalid email address.";

In this example, we check if the form has been submitted and if the email field exists. We then sanitize the email to remove any illegal characters and validate it using the FILTER_VALIDATE_EMAIL filter. If the email is valid, we can proceed with the form submission. If not, we display an error message.

It’s important to note that this is just one example of PHP validation code and there are many other ways to validate form data. The specific validation code will depend on the requirements of your project.

You may also like...

Popular Posts

Leave a Reply

Your email address will not be published. Required fields are marked *