How to find out if a string contains only numbers or also letters
Heiko Merz
Hey,
we want to set up a rule that checks in the Business Partner Master Data on ADD and/or UPDATE if the BP Code is numeric or if it contains letters.
In our philosophy only numbers are allowed.
How can I check if the string contains only numbers and not letters also ?
Thanks for a short answer.
Heiko
Anders Olsson
Hello Heiko,
Regular expressions would normally be used for such things but in this case you can use the simpler TryParse static method of the Int32 class:
string cardcode = "123456";
bool isNumeric = false;
int tmp;
if (int.TryParse(cardcode, out tmp))
{
isNumeric = true;
}
Regards,
Anders
0
Please sign in to leave a comment.
Comments
0 comments