Asp – Stopping MaskedEditExtender from validating input in asp.net

ajaxasp.net

I have an asp.net textbox and a MaskedEditExtender control attached to it. The textbox is used for date input. The MaskedEditExtender has MaskType="Date" Mask="99/99/9999".

When the form is submitted with an invalid date, the browser shows a Javascript error "… string was not recognized as a valid datetime".

I know why the error shows up. Is there a way to use the extender to just control what the user enters and not validate or convert the input?

Best Answer

on the text box you and set up a keypress function.

Validate if the key pressed is a number String.fromCharCode(event.which) or event.keycode (ie or FF)

Then can check that the text box is contains valid code and format.

If invalid you can set to a default that is valid or just prevent the keypress by using preventDefault()

if invalid format can disable the submit button also ....

Good luck

Related Topic