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

onsoftAdilsonjose's avatar

regex validation in laravel(getting this error (preg_match(): Delimiter must not be alphanumeric or backslash))

Hi dev am trying to validate this number true request in laravel 5.8 But am Getting this error... preg_match(): Delimiter must not be alphanumeric or backslash... Apreciate de Help!!!

this is the number that i want to validate 005866373LA012 'nif' => ['required', 'regex:d({9}[A-Z]+\d{3})']

9number follow by 2 letters and 3 numbers!!

my request class .... public function rules() { return [ 'nome' => ['required'], 'gestor' => ['required'], 'numerodeConta' => ['required'], 'tipo' => ['required'], 'Pais' => ['required'], 'Provincia' => ['required'], 'Email' => ['required', 'string', 'email', 'max:255', 'unique:empresaparticular'], 'telemovel' => ['required', 'max:9', 'unique:empresaparticular'], 'nif' => ['required', 'regex:d({9}[A-Z]+\d{3})']

    ];
}
0 likes
3 replies
laracoft's avatar

Please format your code properly. It is really hard to read.

Please or to participate in this conversation.