Home > database >  How can I format url input Laravel
How can I format url input Laravel

Time:10-12

Hey I need to change the format of url when a client inserts an url to the input box. When I fill the input field with a url "www.example.com" an error message appears. The correct format for the url would be "https://www.example.com".

  <div>
      <x-jet-label for="website" value="{{ __('main.Website') }}"/>
      <x-jet-input id="website" type="text"
                         wire:model.defer="website" autocomplete="website"/>
   </div>

This is the fortify part.

  'website' => ['nullable', 'url'],

I need to make both of them valid, both with and without the https part.

CodePudding user response:

You can use your own regex like this:

'website' => ['nullable','regex:/[(http(s)?):\/\/(www\.)?a-zA-Z0-9@:%._\ ~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_\ .~#?&//=]*)/i']

This is a regex link you can customize it as you need!

URL regular expression

  • Related