get_api_url regex is wrong
-
The regex check in get_api_url() is wrong as it’s not accepting hostnames that contain a dash (“-“). For example, I wanted to test against the UAT environment of “fts-uat.cardconnect.com” and this hostname did not pass the regex check.
It would probably be better to use PHP’s FILTER_VALIDATE_DOMAIN validator instead of writing your own regex.
Alternatively, “
^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]*[A-Za-z0-9])$
” seems to be a widely accepted regex for hostname checking.I updated my local code to use “
/^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]*[A-Za-z0-9]):[0-9]+$/
“
- The topic ‘get_api_url regex is wrong’ is closed to new replies.