laravel check if string is url
if (filter_var($string, FILTER_VALIDATE_URL)) {
// you're good
}
laravel check if string is url
if (filter_var($string, FILTER_VALIDATE_URL)) {
// you're good
}
laravel validation types
# <values> = foo,bar,...
# <field> = array field
# <characters> = amount of characters
# accepted # active_url
# after:<tomorrow> # after_or_equal:<tomorrow>
# alpha # alpha_dash
# alpha_num # array
# bail # before:<today>
# before_or_equal:<today> # between:min,max
# boolean # confirmed
# date # date_equals:<today>
# date_format:<format> # different:<name>
# digits:<value> # digits_between:min,max
# dimensions:<min/max_with> # distinct
# email # ends_with:<values>
# exclude_if:<field>,<value> # exclude_unless:<field>,<value>
# exists:<table>,<column> # file
# filled # gt:<field>
# gte:<field> # image
# in:<values> # in_array:<field>
# integer # ip
# ipv4 # ipv6
# json # lt:<field>
# lte:<field> # max:<value>
# mimetypes:video/avi,... # mimes:jpeg,bmp,png
# min:<value> # not_in:<values>
# not_regex:<pattern> # nullable
# numeric # password:<auth guard>
# present # regex:<pattern>
# required # required_if:<field>,<value>
# required_unless:<field>,<value> # required_with:<fields>
# required_with_all:<fields> # required_without:<fields>
# required_without_all:<fields> # same:<field>
# size:<characters> # starts_with:<values>
# string # timezone
# unique:<table>,<column> # url
# uuid
laravel custom validation check if valid url
I have created a custom Validator like:
Validator::extend('german_url', function($attribute, $value, $parameters) {
$url = str_replace(["ä","ö","ü"], ["ae", "oe", "ue"], $value);
return filter_var($url, FILTER_VALIDATE_URL);
});
My rules contain now:
"url" => "required|german_url,
Also don't forget to add the rule to your validation.php file
"german_url" => ":attribute is not a valid URL",
laravel check if string is url
<?php
$regex = "((https?|ftp)\:\/\/)?"; // SCHEME
$regex .= "([a-z0-9+!*(),;?&=\$_.-]+(\:[a-z0-9+!*(),;?&=\$_.-]+)?@)?"; // User and Pass
$regex .= "([a-z0-9-.]*)\.([a-z]{2,3})"; // Host or IP
$regex .= "(\:[0-9]{2,5})?"; // Port
$regex .= "(\/([a-z0-9+\$_-]\.?)+)*\/?"; // Path
$regex .= "(\?[a-z+&\$_.-][a-z0-9;:@&%=+\/\$_.-]*)?"; // GET Query
$regex .= "(#[a-z_.-][a-z0-9+\$_.-]*)?"; // Anchor
if(preg_match("/^$regex$/i", $url)) // `i` flag for case-insensitive
{
return true;
}
?>
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us