PHP eregi() Function

Hello dear readers! welcome back to another section of our tutorial on PHP. In this tutorial guide, we will be discussing about the PHP eregi() Function.

The PHP eregi() function searches throughout a string specified by pattern for a string specified by string. Search with this function is not case sensitive. The eregi() can be specifically very useful when checking for the validity of strings, such as password.

The optional input parameter regs contains an array of all matched expressions that were grouped by parentheses in the PHP's regular expression.

RECOMMENDED POST: PHP ereg_replace() Function


The following is the syntax for the eregi() function -

int eregi(string pattern, string string, [array regs]);

Return Value

  • It returns true if the pattern is validated, otherwise false.


Following is a simple example -

   $password = "abc";
   if (! eregi ("[[:alnum:]]{8,10}", $password))
      print "Invalid password! Passwords must be from 8 - 10 chars";
   } else {
      print "Valid password";


When the above code is executed, it will produce the following result -

Invalid password! Passwords must be from 8 - 10 chars


Alright guys! This is where we are rounding up for this tutorial post. In our next tutorial guide, we are going to be discussing about the PHP eregi_replace() Function.

Feel free to ask your questions where necessary and i will attend to them as soon as possible. If this tutorial was helpful to you, you can use the share button to share this tutorial.

Follow us on our various social media platforms to stay updated with our latest tutorials. You can also subscribe to our newsletter in order to get our tutorials delivered directly to your emails.

Thanks for reading and bye for now.