mardi 6 octobre 2015

Regex, accept an array of strings only if is composed of digits

I'm trying to write an if condition that only accepts an string array if all its elements are digits. If is not made of digits it should return "incorrect input" in else. Later I will turn those digits into integers. This is what I have wrote.

string = []
if string == /^[\d]$/
  m = string.split(",").map(&:to_i).sort

Is not working, can someone tell me what I'm doing wrong? Thank you.

Aucun commentaire:

Enregistrer un commentaire