IT & Programming

Laravel URL validation without http or https

Laravel offers a built-in function to validate a url as shown below:

'website' => 'required|url'

But problem is that it can not validate www.example.com because there is no http:// or https:// at the start of url. In this case you can use a solution with regex.

'website' => 'required|regex:/^(https?:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?$/'

Leave A comment

Email address is optional and will not be published. Only add email address if you want a reply from blog author.
Please fill required fields marked with *