Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 268
  • Last Modified:

Strip characters from number

Hi, I want the user to be able to enter any form of number in my price textbox and I will automatically strip anything that is not an integer.

I obviously can't mand a string.replace for every character, so is there a way to use a regexp to say anything that isnt 0-9?

This will match any unsigned integer:   ^\d*$     So is there a way to say   if(! ^\d*$)?

Thanks, Dave
0
KaiserSose
Asked:
KaiserSose
2 Solutions
 
gregoryyoungCommented:
you could just say .ToCharArray() and then use if char >= '0' && char <= '9' to determine if its numeric ...

or you could just use Char.IsNumber()
0
 
esteban_felipeCommented:
Hi KaiserSose,

string result = Regex.Replace(input,"\\d",String.Empty)

Esteban Felipe
www.estebanf.com
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now