views:

297

answers:

2

Hello, I am wanting to have a numbers/currency only textbox control.

So basically it should accept this kind of input

$123
523,100
$12.50
85.59

and convert this to

123
523100
12.50
85.59

and should not accept this input

F12
309$2342
,102

I have looked at validator controls but I would like to this conversion/checking completely from the client side. What would be the best way of doing this?

I also would like a clientside error(message box or something) popped up if they try to enter invalid data and prevent them from leaving the bad data in the textbox. and then when they get out of focus of the textbox it automatically converts the data into a flat number from the client side.

How would I get started in doing this? Is there something in ASP.Net that can help me? Would I need to just use the onfocus event or what event would be preferable from javascript to validate this? I'm rather inexperienced in Javascript also.. so I apologize if this is a bit noobish.

And yes, I will also validate on the server-side

+1  A: 

You could try validating values inside a textbox using isNaN() to check if the value is a number, after each keystroke.

Anyways, this issue has been answered before here: http://stackoverflow.com/questions/18082/validate-numbers-in-javascript-isnumeric

Joel Alejandro
A: 

Relying on client-side validation is a security risk if you need certain inputs rejected.

You could use the MaskedEditExtender or FilteredTextBox if you're using MS Ajax with your site. Otherwise there are lots of great javascripts out there to do client validation, especially for use with jQuery.

Just don't ignore validation on the server side.

womp