validation - Getting started with PHP/Laravel - Adding Http:// and Https:// on to URL Path -
i attempting have input field adding website/url. want require submit form www.domainname.com; however, after submission want add on http:// or https:// if not added person submitting form.
the validation along lines of following,
public function name($id) { $input = input::all(); $validator = validator::make( $input, array( 'website' => 'active_url', ) ); }
for work if statement needed. have tried inserting along lines of code listed below, have not had luck.
if (!preg_match("~^(?:f|ht)tps?://~i", $url)) { $url = "http://" . $url; }
i new php , starting use laravel, apologize in advance if there confusion or lack of information. appreciated.
this should work:
if (stripos($url, "http://") === false && stripos($url, "https://") === false) { $url = "http://" . $url; }
stripos
case-insensitive, shouldn't matter if user typed in lowercase letters or not in url prefix.
Comments
Post a Comment