Tutorials Point

  Learning PHP
  Advanced PHP
  PHP Function Reference
  PHP Useful Resources
  Selected Reading

Copyright © 2014 by tutorialspoint

  Home     References     Discussion Forums     About TP  

PHP Function eregi()




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

Definition and Usage

The eregi() function searches throughout a string specified by pattern for a string specified by string. The search is not case sensitive. Eregi() can be particularly useful when checking the validity of strings, such as passwords.

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

Return Value

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


Following is the piece of code, copy and paste this code into a file and verify the result.


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

This will produce following result

Invalid password! Passwords must be from 8 - 10 chars

previous Printer Friendly