Nida Akram
Nida Akram

Reputation: 362

preg_match(): Compilation failed: nothing to repeat at offset 1 in laravel

preg_match():Compilation failed in my code.

Preg match expression in my controller is

   'phoneno' => 'required|regex:/(+92)[0-9]{10}/',

Please tell me what is wrong with the regex.

Upvotes: 0

Views: 2043

Answers (1)

Vivendi
Vivendi

Reputation: 21057

You need to escape the + character. You want to match on a phone number starting with +92. But the + character means that it expects 1 or more of the preceding character. Which in this case you don't want.

So in short, change it to this:

/(\+92)[0-9]{10}/

Upvotes: 3

Related Questions