C# Char IsDigit() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
Char

Definition

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);
CallWhat 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

ParameterDescription
cRequired. Character to test.
s, indexOptional. Character at index in s.

Return Value

Return ValueDescription
trueDecimal digit.
falseNot 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));
    }
}

How It Works

  1. Digit seven. ASCII 7 is a decimal digit.
  2. Letter fails. A is not a digit.
  3. Boolean print. Console shows True/False.
  4. 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));
    }
}

How It Works

  1. Fraction glyph. ½ is numeric but not a decimal digit.
  2. IsDigit false. Nd category does not include this character.
  3. IsNumber true. Broader numeric categories match.
  4. 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);
    }
}

How It Works

  1. Character loop. Inspect every char in the PIN.
  2. Fail fast. Break when a non-digit appears.
  3. All good. 4096 is only digits.
  4. 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.
Yes with Char.IsDigit(s, index).
No. Signs and decimal points are not digits.
When you want only ASCII 0–9 (.NET 7+).

Next: IsHighSurrogate()

Return true when the character is a UTF-16 high surrogate with System.Char.

IsHighSurrogate() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful