[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

RegularExpression for Numbers with no decimal points in ASP.net text control

Posted on 2016-11-08
11
Medium Priority
?
70 Views
Last Modified: 2016-11-09
What is the ValidationExpression to be used for a ASP.net text box  control to ensure only whole numbers are accepted (0 to 9) without any decimals?

I am using the following ValidationExpression

"^[0-9]+$"
0
Comment
Question by:Member_2_7967119
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
  • 3
11 Comments
 
LVL 53

Expert Comment

by:Rgonzo1971
ID: 41878256
Hi,

I think it's fine, do you want thousand separators
Shorter
"^\d+$"

Open in new window


Regards
0
 
LVL 32

Accepted Solution

by:
Pawan Kumar earned 2000 total points
ID: 41878331
You need below if (  Regex.IsMatch("12345", @"^[0-9]*$" ))

 if (  Regex.IsMatch("12345", @"^[0-9]*$" ))
                
                 Console.WriteLine("match - [0-9]");
            
 else            
                
                Console.WriteLine("Other");

Open in new window


Hope it helps!!
0
 
LVL 53

Expert Comment

by:Rgonzo1971
ID: 41878338
I wouldn' t use
@"^[0-9]*$"

since it matches empty strings
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 32

Expert Comment

by:Pawan Kumar
ID: 41878340
Thank you Rgonzo1971. I think user will not be allowed to click on the submit button in that case. We can also use below if thats the issue.

            string str = "";
            if ( str.Length > 0 && Regex.IsMatch(str, @"^[0-9]*$" ))
                
                 Console.WriteLine("match - [0-9]");
            
            else            
                
                Console.WriteLine("Other");

Open in new window

0
 

Author Comment

by:Member_2_7967119
ID: 41880462
^\d+$ fails since it allows empty space. I want only whole numbers without decimals to go through. Thanks.
0
 
LVL 32

Expert Comment

by:Pawan Kumar
ID: 41880463
Hi Author,
Have you tried mine code?

Regards,
Pawan
0
 
LVL 53

Expert Comment

by:Rgonzo1971
ID: 41880478
Cannot replicate your error
        string str = "";
        if ( Regex.IsMatch(str, @"^\d+$"))

            Console.WriteLine("match - [0-9]");

        else

            Console.WriteLine("Other");

Open in new window

0
 

Author Comment

by:Member_2_7967119
ID: 41881683
Pawan,

^[0-9]*$ does work. Thank you
0
 
LVL 32

Expert Comment

by:Pawan Kumar
ID: 41881687
Can you provide us few sample strings you are using ?
0
 

Author Closing Comment

by:Member_2_7967119
ID: 41881688
Thank you for your help.
0
 
LVL 32

Expert Comment

by:Pawan Kumar
ID: 41881689
ohh !! Great ..
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Suggested Courses

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question