?
Solved

asp.net: validator for an integer

Posted on 2003-03-24
8
Medium Priority
?
1,094 Views
Last Modified: 2008-03-06
hey, im using a rangevalidator right now for an integer field, and it works well enough. however, if someone enters "12,000" or "17,104,206", id like  it to recognize it as an integer still.

i could do a regular expression validator for it, and then check on the server side as well to remove commas before saving it as an integer field in the database.

i was hoping there would be a way to have the rangevalidator recognize all valid integers in a range. if that isn't possible, does anyone have a regular expression handy for recognizing any validly formatted integers? (0 or greater is fine).

thanks,

--tekc
0
Comment
Question by:tekcircpup
[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
8 Comments
 
LVL 4

Expert Comment

by:whammy
ID: 8199292
If you're concerned about the comma placement, then it might be a tiny bit more work (although I have a regex like that laying about somewhere)... I'd just make sure it's all digits (once you remove the commas):

^\d+$
0
 

Author Comment

by:tekcircpup
ID: 8199303
i do want to be sure about comma placement, just to warn someone if they enter 12,00. they probably meant 12,000, so keeping it as 1200 would be less than ideal.
0
 
LVL 4

Expert Comment

by:whammy
ID: 8199414
Wow, it took me forever to find, but there are a couple of solutions in this post:

http://codingforums.com/showthread.php?s=d24ec2c921e5a57a382e4fc1312c9a2f&threadid=13577&perpage=15&highlight=currency&pagenumber=2

The main highlight from my post being:

         var objRegExp = new RegExp('(-?\[0-9]+)([0-9]{3})');
         while(objRegExp.test(asdf) asdf = asdf.replace(objRegExp,'$1,$2');
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 4

Expert Comment

by:whammy
ID: 8199416
P.S. replace "asdf" with the string you're testing! ;-)
0
 
LVL 4

Expert Comment

by:whammy
ID: 8199423
P.P.S. This is in javascript, but I have run into very few problems porting this kind of stuff to C# with .NET (I'm assuming that's what you're using).

Hope this helps. ;-)
0
 

Author Comment

by:tekcircpup
ID: 8199458
looks great. im actually using vb with asp.net, but shouldnt be a problem to port it. ill get it in there and verify it works tomorrow.

thanks!

--tekc
0
 
LVL 4

Accepted Solution

by:
whammy earned 200 total points
ID: 8199480
I hope it works for you. If not it shouldn't take much modification (disregarding VB.NET, I am not familiar with regex's in VB.NET yet. P.S. it looks like I left out a paren in the "if" statement... oops - but that's just cheese).

Let me know how that works...
0
 

Author Comment

by:tekcircpup
ID: 8608442
sorry, got distracted by another project, and havent looked at this in forever!
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

762 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