FILTER_VALIDATE_REGEXP constant in PHP

PHPProgrammingServer Side Programming

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!
raja
Published on 04-Dec-2018 07:17:38
Advertisements