| |

VerySource

 Forgot password?
 Register
Search
View: 1765|Reply: 13

Determine if it is a number

[Copy link]

1

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-1-2 22:50:01
| Show all posts |Read mode
There is NAME: I want to determine whether the characters entered by the user are numbers or not.
(I am a newbie just learning C #, please help!)
Reply

Use magic Report

0

Threads

24

Posts

20.00

Credits

Newbie

Rank: 1

Credits
20.00

 China

Post time: 2020-1-2 23:54:01
| Show all posts
Regular expression
using System.Text

if (Regex.IsMatch (this.inputTextbox.Text, @ "^\d + $")
{
// is a number
}
else
{
// not a number
}
Reply

Use magic Report

0

Threads

56

Posts

21.00

Credits

Newbie

Rank: 1

Credits
21.00

 China

Post time: 2020-1-3 00:24:01
| Show all posts
Use regular

Regex regex = new Regex (@ "^\d + $");
if (regex.IsMatch (name.Text.Trim ()))
{
   // ...
}
Reply

Use magic Report

0

Threads

110

Posts

63.00

Credits

Newbie

Rank: 1

Credits
63.00

 China

Post time: 2020-1-3 15:24:01
| Show all posts
using System.Text.RegularExpressions;

if ((Regex.Match (this.TextBox1.Text.Trim (), @ "^\d + $")). Success)
            {
                // Meet the requirements
            }
            else
            {
                //non-compliant
            }
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-1-4 14:33:01
| Show all posts
using System.Text.RegularExpressions;

if ((Regex.Match (this.TextBox1.Text.Trim (), @ "^\d + $")). Success)
            {
                // OK
            }
            else
            {
                // ERROR,
            }
Reply

Use magic Report

0

Threads

15

Posts

9.00

Credits

Newbie

Rank: 1

Credits
9.00

 China

Post time: 2020-1-4 16:30:01
| Show all posts
The easiest way:

if (Microsoft.VisualBasic.Information.IsNumeric ("asdasds"))
MessageBox.Show ("yes");
else
MessageBox.Show ("no");
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-1-4 23:30:01
| Show all posts
^\s *\d + $ one or more numbers
 ^\s *\d * $ zero or more digits
Reply

Use magic Report

0

Threads

10

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

Post time: 2020-1-19 14:00:02
| Show all posts
C # determine whether a string is a number
http://www.cnblogs.com/zm235/archive/2006/09/23/512742.html
Reply

Use magic Report

1

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

 Author| Post time: 2020-7-23 17:00:01
| Show all posts
Thank you all!!!!!
But can you help me explain what Regex.Match(this.TextBox1.Text.Trim(), @"^\d+$")).Success means, especially @"^\d+$" is there any other way to write it?
Reply

Use magic Report

0

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-7-23 17:45:01
| Show all posts
Use regular expressions directly in the keypress process
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list