In C#, Char.IsDigit returns true for Unicode decimal digits (category Nd). ASCII '0'–'9' are included, as are decimal digits from other scripts.
Prefer IsDigit when validating typical numeric input characters. Use IsNumber only if you also want fractions, superscripts, and similar numeric symbols.
This is a static member of System.Char. You call it with the type name, such as Char.IsDigit(...) or char.IsDigit(...). A char holds one 16-bit UTF-16 code unit.
Syntax
Pass the character you want to test.
C#
char c = '7';
bool ok = Char.IsDigit(c);
Call
What it does
Char.IsDigit(c)
True if c is a decimal digit.
Char.IsDigit(s, i)
Tests s[i].
IsAsciiDigit (.NET 7+) is limited to ASCII 0–9.
Library declarations
C#
public static bool IsDigit(char c);
public static bool IsDigit(string s, int index);
Parameters
Parameter
Description
c
Required. Character to test.
s, index
Optional. Character at index in s.
Return Value
Return Value
Description
true
Decimal digit.
false
Not a decimal digit.
C# Examples
Example 1 — Check ASCII Digits
Test digits and a letter.
C#
using System;
class Program {
static void Main() {
char c = '7';
char a = 'A';
Console.WriteLine("7: " + Char.IsDigit(c));
Console.WriteLine("A: " + Char.IsDigit(a));
}
}
Output
7: True
A: False
How It Works
Digit seven. ASCII 7 is a decimal digit.
Letter fails. A is not a digit.
Boolean print. Console shows True/False.
Everyday use. Ideal for simple numeric character checks.
Example 2 — Digit Versus Number
Compare IsDigit and IsNumber on a vulgar fraction character.
C#
using System;
class Program {
static void Main() {
char half = '\u00BD'; // ½
Console.WriteLine("IsDigit: " + Char.IsDigit(half));
Console.WriteLine("IsNumber: " + Char.IsNumber(half));
}
}
Output
IsDigit: False
IsNumber: True
How It Works
Fraction glyph. ½ is numeric but not a decimal digit.
IsDigit false. Nd category does not include this character.
IsNumber true. Broader numeric categories match.
Pick carefully. Know which helper matches your validation rules.
Example 3 — All Characters Are Digits
Verify a PIN string contains only digits.
C#
using System;
class Program {
static void Main() {
string pin = "4096";
bool allDigits = true;
foreach (char ch in pin) {
if (!Char.IsDigit(ch)) {
allDigits = false;
break;
}
}
Console.WriteLine("PIN ok: " + allDigits);
}
}
Output
PIN ok: True
How It Works
Character loop. Inspect every char in the PIN.
Fail fast. Break when a non-digit appears.
All good. 4096 is only digits.
Length separate. IsDigit does not enforce PIN length—check that yourself.
Frequently Asked Questions
No. IsNumber includes additional numeric characters beyond decimal digits.
It accepts Unicode decimal digits; ASCII 0–9 are the common case. Use IsAsciiDigit for ASCII-only.