Search code examples
phpregexvalidationdigits

Validate that a string starts with specified numbers then a certain number of digits


$output = preg_replace( '/[^0-9]/', '', $string );

How can I change the above line to only accept 11 digit long numbers that must start with either 01, 02, 03, 05, 07 or 08, but NOT 04, 06, 09?


Solution

  • Use following pattern:

     /^0[123578]{1}[0-9]{9}$/