Check if URL is from a certain website

后端 未结 2 1667
情书的邮戳
情书的邮戳 2021-01-29 11:52

Problem

The user can submit a form where he can submit a link to sitea.com. Now what I want to do is check if the user actually submitted an URL coming fr

2条回答
  •  南方客
    南方客 (楼主)
    2021-01-29 12:34

    This might not be a job for regexes, but for existing tools in your language of choice. Regexes are not a magic wand you wave at every problem that happens to involve strings. You probably want to use existing code that has already been written, tested, and debugged.

    In PHP, use the parse_url function.

    Perl: URI module.

    Ruby: URI module.

    .NET: 'Uri' class

提交回复
热议问题