a = a.chomp.split("") b = b.chomp.split("") c = 0 if a[0] == "0" && a.size != 1 c = 1 else a.each_index do |i| if a[i] =~ /\D/ c = 1 break end end end if c == 1 elsif b[0] == "0" && b.size != 1 c = 1 else b.each_index do |i| if b[i] =~ /\D/ c = 1 break end end end if c == 0 if a.join.to_i <= 12345 && b.join.to_i <= 12345 puts "OK" else puts "NG" end else puts "NG" end