|
.net
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Using Validation controls to check for NON NUMERIC input. (This should be easy!)'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? 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: PLB***@PeterBlum.com Creator of "Professional Validation And More" at http://www.peterblum.com/vam/home.aspx "Chad" <chad.dokmanov***@unisys.com> wrote in message I have a textbox control, txtMeasurement, that I want to allow only numeric news:doudei$qb7$1@trsvr.tr.unisys.com... 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? 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 ***
Other interesting topics
Application_Start Question
Resources and class libraries ViewState: why? Nested asp.net application Allow multiple image swap onmouseover Help: Why <mobile:label> doesn't render HTML tag? What caused the postback? Access to a HiddenFiled in a Content control from javaScript ASP.NET 2.0 ICallbackEventHandler masking url in datagrid hyperlink column in status bar |
|||||||||||||||||||||||