Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

arunasrim's avatar

how to consider 01, 02, 03 as integers in lumen validations?

we have an api with param accepting values only integers, how ever it has to allow numbers which are preceded by 0 as integers. is there any specific rule directive we have in lumen.

0 likes
1 reply
LaryAI's avatar
LaryAI
AI
Best Answer
Level 58

Yes, you can use the regex rule in Lumen's validation to allow numbers preceded by 0 as integers. Here's an example:

$request->validate([
    'number' => ['required', 'regex:/^[0-9]+$/'],
]);

This will validate that the number parameter is required and contains only digits (0-9). The regex rule uses a regular expression to match the pattern. The ^ and $ characters indicate the start and end of the string, respectively. The + character means one or more occurrences of the preceding character or group (in this case, digits).

With this validation rule, numbers like 01, 02, and 03 will be considered as integers.

Please or to participate in this conversation.