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

Node.js examples for String:String Value

Description

Check if a string is a valid size string

Demo Code


  isSize : function(s) {
    return this.test(s, '^[0-9]+(%|in|cm|mm|em|ex|pt|pc|px)?$');
  },/*from  ww w  .java 2s  .co  m*/

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

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

Related Tutorials