import re

def is_valid_URL(str):
    pattern = re.compile(
        r'^(https?://|ftp://|www\.)'
        r'([a-zA-Z0-9.-]+)'
        r'(\.[a-zA-Z]{2,})'
        r'(:[0-9]+)?'
        r'(/[^\s]*)?$'
    )
    return bool(pattern.match(str))