This article example describes how C# can verify whether a given string is a number. Share it for your reference. The specific analysis is as follows:
This C# code is used to verify whether the given string is a number and cannot be used to verify negative numbers. Only numbers and decimal points can appear in the string. Otherwise, it is considered that it is not a number and does not verify the length of the number. That is to say, no matter how long the given string is, even if it is 10,000 characters, it can pass the verification, so the verified string may not necessarily be converted into the int type and Int64 type of C#.
/// <summary> /// Verify that it is a number/// </summary> /// <param name="number">number to verify</param>public static bool IsNumber(string number) { //If it is empty, the verification is considered unqualified if (IsNullOrEmpty(number)) { return false; } //Clear the spaces in the string to be validated number = (); //Mode string string pattern = @"^[0-9]+[0-9]*[.]?[0-9]*$"; //verify return (number, pattern); }
I hope this article will be helpful to everyone's C# programming.