Regex to validate range of numbers from 50 to 1000 with step of 50 [closed]

Why use regex? That will only make it complex

Use an array of the range and in_array.

$range = range(50,1000,50);

$input = 34;   
var_dump(in_array($input, $range)); // false

$input = 150;
var_dump(in_array($input, $range));//true

The regex version is this:

Either a tree digit number that ends with 50 or 00 or exactly 1000

$input = 950;

var_dump(preg_match("/\b\d{0,1}[5|0]0\b|\b1000\b/", $input));

Browse More Popular Posts

Leave a Comment