3

when i use 'url' validation in laravel request then give me error.

preg_match(): Compilation failed: invalid range in character class at offset 1828

$this->validate($request, [
   'posting_article_url' => 'nullable|url',
]);

it is occurred in php 7.3. in php 7.2 it is working fine.

when i replace 'url' validation with 'regex:pattern' validation then working fine.

$this->validate($request, [
   'posting_article_url' => 'nullable|regex:/^(https?:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?$/',
]);

Thanks in advance!

Jinal Somaiya
  • 1,931
  • 15
  • 29
  • Can you put here some line of code? At least the preg_match(...) line and the used values. – Marcel Preda Apr 16 '19 at 10:38
  • As I've said: it will help the line with preg_match() and the values used, especially the 1st parameter $pattern. – Marcel Preda Apr 16 '19 at 10:56
  • The complete error message should be something like: preg_match(): Compilation failed: invalid range in character class at offset 1828 FILE.php on line NNN On line NNN you should find the preg_match() call. Put here the respective line, and print the values passed to preg_match(). – Marcel Preda Apr 16 '19 at 11:33
  • sorry but it is a php 7.3 issue. – Jinal Somaiya Apr 16 '19 at 11:48
  • 1
    Probable you are hit by this change 7.3 vs. 7.2 : https://hackernoon.com/deprecations-and-changes-for-php-7-3-avoid-errors-7a5c4dbeaa8b , check "PCRE to PCRE2 migration" , and few lines below you you will find an example which works no more in 7.3 . Because of that is important to know the vallues passed to preg_match() . But if you don't provide the exact line of code and the values passed it will be hard to guess what is the reason. – Marcel Preda Apr 16 '19 at 11:54
  • @miken32 I don't see a poorly placed hyphen on this one. I can't replicate. Do you see something that I don't? – mickmackusa May 10 '19 at 05:32
  • @mickmackusa I’m assuming it’s inside the Laravel code somewhere. Probably the actual answer on this one is to upgrade Laravel. – miken32 May 10 '19 at 13:11
  • I chose "cannot replicate" instead of dupe hammering this one (I hammered all of your others) -- but my vote was the 5th, so same effect. – mickmackusa May 10 '19 at 13:14

0 Answers0