btmgreg
Well-known member
Hey all,
I've been trying to use the following template as a custom validator. The rest seem to be working fine, but I think this one is because the url has a hyphen inside like this -
I have tried adding a hyphen to this code with no results -
/(?P<id>[a-z0-9\_.]+)$#i', $value, $match))
I've tried a few variations online but had no luck. Anyone got any tips to handle a validator where the link has hyphens or other symbols other than alphanumeric?
Thank you
I've been trying to use the following template as a custom validator. The rest seem to be working fine, but I think this one is because the url has a hyphen inside like this -
Code:
<?php
namespace XF\Validator;
use function is_string;
class Linkedin extends AbstractValidator
{
public function isValid($value, &$errorKey = null)
{
if (!preg_match('/^[a-z0-9_]+$/i', $value))
{
$errorKey = 'please_enter_valid_twitter_name_using_alphanumeric';
return false;
}
return true;
}
public function coerceValue($value)
{
if (is_string($value) && $value && $value[0] == '@')
{
$value = substr($value, 1);
}
else if (preg_match('#linkedin\.com/in/(?P<id>[a-z0-9\_.]+)$#i', $value, $match))
{
$value = $match['id'];
}
return $value;
}
}
/(?P<id>[a-z0-9\_.]+)$#i', $value, $match))
I've tried a few variations online but had no luck. Anyone got any tips to handle a validator where the link has hyphens or other symbols other than alphanumeric?
Thank you