Check if a string is a valid id string - Node.js String

Node.js examples for String:String Value

Description

Check if a string is a valid id string

Demo Code

  isId : function(s) {
    return this.test(s, '^[A-Za-z_]([A-Za-z0-9_])*$');
  },/* ww  w.  j a v  a  2s. c om*/

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

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

Related Tutorials