FILTER_VALIDATE_REGEXP constant in PHP


The FILTER_VALIDATE_REGEXP constant validates a value against a Perl-compatible regular expression.

Options

  • regexp − The regular expression to validate against.

Return

The FILTER_VALIDATE_REGEXP constant does not return anything.

Example

Live Demo

<?php
   $val="example.com"; 
   $res = array("options"=>array("regexp"=>"/^ex(.*)/"));
   if(filter_var($val, FILTER_VALIDATE_REGEXP,$res)) {
      echo "Matched String!";
   } else {
      echo "Not a Matched String!";
   }
?>

The following is the output.

Matched String!

Updated on: 30-Jul-2019

584 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements