Validating a URL in Node.js

后端 未结 4 1491
我在风中等你
我在风中等你 2020-12-24 08:53

I want to validate a URL of the types:

  • www.google.com
  • http://www.google.com
  • google.com

4条回答
  •  情深已故
    2020-12-24 09:04

    There's a package called valid-url

    var validUrl = require('valid-url');
    
    var url = "http://bla.com"
    if (validUrl.isUri(url)){
        console.log('Looks like an URI');
    } 
    else {
        console.log('Not a URI');
    }
    

    Installation:

    npm install valid-url --save
    

    If you want a simple REGEX - check this out

提交回复
热议问题