Checks number against regex and compares match length

 ==== Attributes

 * +number+ - phone number for validation
 * +regex+ - regex for perfoming a validation
548811
def number_match?(number, regex)
      match = number.match(cr("^(?:#{regex})$"))
      match && match.to_s.length == number.length
    end
881948
function computeCombinationLength(elementNumber, combinationLength) {
    elementNumber = Number(elementNumber);
    combinationLength = Number(combinationLength);
    if (!_regex.regex.positiveInteger.test(String(elementNumber))) {
        throw new Error("elementNumber should be positiveNumber but got " + elementNumber);
    }
    if (!(_regex.regex.positiveInteger.test(String(combinationLength)) || combinationLength === 0)) {
        throw new Error("elementNumber should be positiveNumber or 0 but got " + combinationLength);
    }
    if (combinationLength > elementNumber) {
        throw new Error("The max value of combinationLength should be " + elementNumber + " but got " + combinationLength);
    }
    if (combinationLength === 0) {
        return 1;
    }
    return computeFactorial(elementNumber) / (computeFactorial(combinationLength) * computeFactorial(elementNumber - combinationLength));
}
127239
function (number, digits) {
    if (typeof number !== "number") { throw "not a number: " + number; }
    var s = number.toString();
    if (number.length > digits) {
      return number.substr(number.length - digits, number.length);
    }
    while (s.length < digits) {
      s = '0' + s;
    }
    return s;
  }
272570
def validate_zip_code(self, value):
        

        if not Type.ZIPCODE_REGEX.match(value):
            raise ValidationError(self.messages['zip_code'])
        return value
316683
function matches(str, match) {
    if (Array.isArray(match)) return match.indexOf(str) > -1;
    return match.test(str);
}
511439
def get_number_matches(self, pattern, source_text='', case=False,
                           regexp=False):
        """"""
        pattern = to_text_string(pattern)
        if not pattern:
            return 0

        if not regexp:
            pattern = re.escape(pattern)

        if not source_text:
            source_text = to_text_string(self.toPlainText())

        try:
            if case:
                regobj = re.compile(pattern)
            else:
                regobj = re.compile(pattern, re.IGNORECASE)
        except sre_constants.error:
            return None

        number_matches = 0
        for match in regobj.finditer(source_text):
            number_matches += 1

        return number_matches
932149
function checkLength(size, schema, key) {
    //Check if it is an int
    if (Number.isInteger(schema[SCHEMALENGTH])) {
      if (size != schema[SCHEMALENGTH]) {
        throw new ValidationException("Size of " + key + " is not correct.");
      }
    } else if (typeof schema[SCHEMALENGTH] == "string") {
      if (
        size < getMin(schema[SCHEMALENGTH], key) ||
        size > getMax(schema[SCHEMALENGTH], key)
      ) {
        throw new ValidationException("Size of " + key + " is not correct.");
      }
    } else {
      throw new ValidationException(SCHEMALENGTH + " cast exception: " + key);
    }
  }
422877
function checkLength(str) {
        var ctm = ctx.measureText(str);
        return ctm.width <= tm.width;
      }
835691
def validate_number(self, number):
        
        if not isinstance(number, str):
            raise ElksException('Recipient phone number may not be empty')
        if number[0] == '+' and len(number) > 2 and len(number) < 16:
            return True
        else:
            raise ElksException("Phone number must be of format +CCCXXX...")
1266031
def is_length(property_name, *, min_length=1, max_length=None, present_optional=False):
    """"""
    def check(val):
      """Checks that a value matches a scope-enclosed set of length parameters."""
      if not val:
        return present_optional
      else:
        if len(val) >= min_length:
          if max_length is None:
            return True
          else:
            return len(val) <= max_length
        else:
          return False

    if max_length:
      message = "must be at least {0} characters long".format(min_length)
    else:
      message = "must be between {0} and {1} characters long".format(min_length, max_length)

    return Validation(check, property_name, message)
683950
def check_errors
      if @value && @value.is_a?(Numeric)
        if @args.is_a?(Hash)

          @args.each do |arg, val|
            case arg
            when :min
              add_error("number must be greater than #{val}") if @value < val
            when :max
              add_error("number must be less than #{val}") if @value > val
            end
          end

        end
      else
        message = (@args.is_a?(Hash) && @args[:message]) || 'must be a number'
        add_error(message)
      end
    end
1070603
function countNumMatches(contents, queryExpr) {
    if (!contents) {
        return 0;
    }
    var matches = contents.match(queryExpr);
    return matches ? matches.length : 0;
}
1132074
function toNumber(value) {
        var _this = this;

        if (validateHelpers.isArray(value)) {
            return value.map(function (a) {
                return _this.toNumber(a);
            });
        }

        var number = parseFloat(value);

        if (number === undefined) {
            return value;
        }

        if (number.toString().length !== value.toString().length && !validateHelpers.isNumeric(value)) {
            return value;
        }

        return validateHelpers.isNumber(number) ? value : number;
    }
850346
function(a, min, max, allowNumbers, msg) {
    return assert((this.assertStringMinLength(a, min, allowNumbers, msg)&&this.assertStringMaxLength(a, max, allowNumbers, msg)), msg);
  }
836001
function() { 
      
      var v = this.getValue(), str_value = inputEx.NumberField.superclass.getValue.call(this);
      
      // empty field
      if (v === '') {
         // validate only if not required
         return !this.options.required;
      }
      
      if (isNaN(v)) {
         return false;
      }
      
      // We have to check the number with a regexp, otherwise "0.03a" is parsed to a valid number 0.03
      return !!str_value.match(/^([\+\-]?((([0-9]+(\.)?)|([0-9]*\.[0-9]+))([eE][+-]?[0-9]+)?))$/) && v >= this.options.min && v <= this.options.max;
      
   }
935851
def valid? number
      raise_on_type_mismatch number
      num, check = split_number(number)
      self.of(num) == check
    end
1060160
function validateNum() {
        var pass = true,
        num = '';

        ['#areacode', '#phnum1', '#phnum2'].forEach(function(id) {
            var $e = $(id),
            val = $e.val();

            if(!val || val.length !== parseInt($e.attr('maxlength'), 10)) {
                pass = false;
                $e.addClass('error');
            }
            else
                num += val;
        });

        if(!pass) return false;

        return num;
    }