469,572 Members | 1,325 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,572 developers. It's quick & easy.

Using Validation controls to check for NON NUMERIC input. (This should be easy!)

I have a textbox control, txtMeasurement, that I want to allow only numeric decimal input. I thought to use a client side validation control to ensure that the data entered is of type "Double".

'Measurement Validation (Range Validator)
Dim MeasurementRangeValidator As New RangeValidator 'validate that the measure is numeric

MeasurementRangeValidator.ControlToValidate = txtMeasurement.ID|
MeasurementRangeValidator.Display = ValidatorDisplay.Dynamic
MeasurementRangeValidator.Type = ValidationDataType.Double|
MeasurementRangeValidator.CssClass = "validatorerrormessage"
MeasurementRangeValidator.MinimumValue = CType(-999999999999, Double).ToString 'essentially allow any value, we are just checking to make sure that it is numeric
MeasurementRangeValidator.MaximumValue = CType(999999999999, Double).ToString

However, if the user types a dash ("-") in the text box, the validation control's edit is passed but my program blows up on the following line:

Dim dblMeasurement as Double = CTYPE(txtMEasurement.Text, Double)

It fails because it is unable to convert a "-" to a Double data type!

By the way, this also does not work:

This function returns TRUE:

BaseCompareValidator.CanConvert("-", ValidationDataType.Double)

but

Dim dblMyDouble As Double = CTYPE("-", Double)

fails!

Is there some way to get the Validation control to fire when and only when the user enters data that cannot be converted to a Double datatype?

Dec 28 '05 #1
2 2692
The RangeValidator only validates once the data is considered well
formatted. In the case of "-", its not a well formatted number.
You need another validator to report a formatting error. That's the
CompareValidator with its Operator=DataTypeCheck and Type=Double

See this article for more on validation: http://aspalliance.com/699.

--- Peter Blum
www.PeterBlum.com
Email: PL****@PeterBlum.com
Creator of "Professional Validation And More" at
http://www.peterblum.com/vam/home.aspx

"Chad" <ch**************@unisys.com> wrote in message
news:do**********@trsvr.tr.unisys.com...
I have a textbox control, txtMeasurement, that I want to allow only numeric
decimal input. I thought to use a client side validation control to ensure
that the data entered is of type "Double".
'Measurement Validation (Range Validator)
Dim MeasurementRangeValidator As New RangeValidator 'validate that the
measure is numeric
MeasurementRangeValidator.ControlToValidate = txtMeasurement.ID|
MeasurementRangeValidator.Display = ValidatorDisplay.Dynamic
MeasurementRangeValidator.Type = ValidationDataType.Double|
MeasurementRangeValidator.CssClass = "validatorerrormessage"
MeasurementRangeValidator.MinimumValue = CType(-999999999999,
Double).ToString 'essentially allow any value, we are just checking to make
sure that it is numeric
MeasurementRangeValidator.MaximumValue = CType(999999999999,
Double).ToString
However, if the user types a dash ("-") in the text box, the validation
control's edit is passed but my program blows up on the following line:
Dim dblMeasurement as Double = CTYPE(txtMEasurement.Text, Double)
It fails because it is unable to convert a "-" to a Double data type!
By the way, this also does not work:
This function returns TRUE:
BaseCompareValidator.CanConvert("-", ValidationDataType.Double)
but
Dim dblMyDouble As Double = CTYPE("-", Double)
fails!
Is there some way to get the Validation control to fire when and only when
the user enters data that cannot be converted to a Double datatype?
Dec 28 '05 #2
Thanks for the response, but I regret to say that your suggestion did
not work.

The result was the same. The Comapre validation control thinks that "-"
or "+" is a valid Double value. However, CTYPE cannot convert it to
store in a Double variable.

*** Sent via Developersdex http://www.developersdex.com ***
Dec 28 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Matthias Lohrer | last post: by
2 posts views Thread by Chris Barrow | last post: by
3 posts views Thread by Gareth | last post: by
7 posts views Thread by Paul | last post: by
2 posts views Thread by Ing. Rajesh Kumar | last post: by
2 posts views Thread by baroque Chou | last post: by
4 posts views Thread by guiromero | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.