Check if a string is a valid absolute url - Node.js String

Node.js examples for String:URL String

Description

Check if a string is a valid absolute url

Demo Code


  isAbsUrl : function(s) {
    return this.test(s, '^(news|telnet|nttp|file|http|ftp|https)://[-A-Za-z0-9\\.]+\\/?.*$');
  },/*from   w w  w  .  j  av a  2 s. c  om*/

  test : function(s, p) {
    s = s.nodeType == 1 ? s.value : s;

    return s == '' || new RegExp(p).test(s);
  }

Related Tutorials