The mb_ereg_match() is an inbuilt function in PHP that is used for matching multibyte strings using regular expressions.
Syntax:
mb_ereg_match(pattern, string, options = null): bool
Parameters: This function has 3 parameters:
- pattern: The pattern parameters define the regular expression
- string: This parameter match or is evaluated by the regular expression pattern.
- option: This parameter defines search regular options.
Return Value: This function returns “true” for matching the string with the regular expression otherwise it will return “false”.
Example 1: The following code demonstrates the PHP mb_ereg_match() function.
PHP
<?php $email = "dachman@gmail.com" ; $pattern = '^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$' ; if (mb_ereg_match( $pattern , $email )) { echo "The email address is valid." ; } else { echo "The email address is invalid." ; } ?> |
Output:
The email address is valid.
Example 2: The following code is another example of the mb_ereg_match() function of PHP.
PHP
<?php $name = "GeekforGeeks" ; // Match Only Characters $pattern = '^[a-zA-Z]+$' ; if (mb_ereg_match( $pattern , $name )) { echo "The name is valid." ; } else { echo "The name is invalid." ; } ?> |
Output:
The name is valid.
Reference: https://www.php.net/manual/en/function.mb-ereg-match.php