Skip to content

Validators

is_valid_url(value, context) ΒΆ

Validate URL pattern.

Parameters:

Name Type Description Default
value
required
context
required

Returns:

Type Description
Source code in ckanext/webview/logic/validators.py
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
def is_valid_url(value, context):
    """
    Validate URL pattern.

    :param value:
    :param context:
    :returns:
    """
    # from https://urlregex.com
    pattern = (
        'http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*(),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+'
    )
    if re.search(pattern, value, re.IGNORECASE):
        return value

    raise toolkit.Invalid(toolkit._('Not a valid URL'))