![Numbers only regex (digits only) C#](https://cdn.prod.website-files.com/6542d8f9e468531067fe9978/65857c5d9726d9f7f52b07c3_61fd92cc2b89c33bb50044c2_icons-regex_numbers-c.png)
Numbers only (digits only)
Numbers only (or digits only) regular expressions can be used to validate if a string contains only numbers.
Basic numbers only regex
Below is a simple regular expression that allows validating if a given string contains only numbers:
Test it!
This is some text inside of a div block.
True
False
Enter a text in the input above to see the result
Example code in C#:
Real number regex
Real number regex can be used to validate or exact real numbers from a string.
Test it!
This is some text inside of a div block.
True
False
Enter a text in the input above to see the result
Example code in C#:
Test it!
This is some text inside of a div block.
True
False
Enter a text in the input above to see the result
Notes on number only regex validation
In C# you can also validate number by trying to parse it: