如何检查URL是否对Codeigniter中的挪威字符有效

I'm building an application in Codeigniter and tried to use valid_url from Form validation library to check if a domain is valid (e.g. "hæi.no"). Since Norwegian characters aren't allowed, this did not work. What would be the best work around to check for valid URLs and allow Norwegian characters, such as "ÆØÅ", "æøå"?

You can create your own form validation library which I personally think is more elegant than using callbacks.

In your controller

$this->load->library(array('form_validation', 'My_form_validation'));

This ensures both of the libraries are loaded, you need them both as MY_Form_validation extends CI_Form_validation

/application/libraries/My_form_validation.php

<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class MY_Form_validation extends CI_Form_validation
{
    /**
     * Reference to the CodeIgniter instance
     *
     * @var object
     */
    protected $CI;

    function __construct($config = array())
    {
        $this->CI =& get_instance();

        parent::__construct($config);
    }

    function series_exists($series_id)
    {
        $this->CI->db
            ->select('COUNT(`id`)')
            ->where('id', $series_id);
        $rows = $this->CI->db->get('series')->result()[0];

        return $rows == 1;
    }
}

You can see the series_exists function in this example, this would be called like a normal validation rule as it only takes one parameter. You would replace this with your own function which must have a unique name, such as my_valid_url.

Add the function name to your validation rules, in my example it would look something like this 'required|integer|series_exists'