How to validate URL with https using regex in laravel

Updated at 18-Aug-2021, By samar

How to validate URL with https using regex in laravel

Hello everyone, in this post we will examine how to solve the "How to validate URL with https using regex in laravel" programming puzzle.

You can validate URL in laravel by creating a regex. You can create your own regex and use regex rules to validate the URL in laravel.
  • Laravel URL validation with https using regex

    //Inside controller's method
    $regex = '/^(https?:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?$/';
    $request->validate([
        'url' => 'required|regex:'.$regex,
    ]);
    

Back to code snippet queries related laravel