This language bar is your friend. Select your favorite languages!

Idiom #137 Check if string contains only digits

Set boolean b to true if string s contains only characters in range '0'..'9', false otherwise.

import "strings"
isNotDigit := func(c rune) bool { return c < '0' || c > '9' }
b := strings.IndexFunc(s, isNotDigit) == -1
b := true
for _, c := range s {
	if c < '0' || c > '9' {
		b = false
		break
	}
}
import std.ascii;
import std.algorithm;
bool b = s.all!isDigit;
std.algorithm.iteration;
std.ascii;
bool b = s.filter!(a => !isDigit(a)).empty;
import Data.Char
b = all isDigit s
var b = /^[0-9]*$/.test(s);
boolean b = s.matches("[0-9]*");
b = tonumber(s) ~= nil
-1
var
  S: String;
  C: Char;
  B: Boolean;

  for C in S do
  begin
    B := C in ['0'..'9'];
    if not B then Break;
  end;
b = s.isdigit()
b = s.count("^0-9").zero?

Do you know the best way to do this in your language ?
New implementation...

Idiom created by

programming-idioms.org