Validate Numeric TextBox Entries Asp.Net
In Asp.Net or Web-Developemnt what is the best way to Vali开发者_Go百科dateTextBox's on a page. The TextChange event (server side) happens after you leave the textbox which is too late. I was going to use a Double.TryParse on server side.
The accepted best practice is to use a Validator control.
The CompareValidator can be used to verify the Data Type by changing the "Operator" property to "DataTypeCheck".
You could also use a RegularExpressionValidator for the same effect.
If you need to do a type check and ensure the value is withing a specified range, you would use a RangeValidator.
Check Regular expression and use RegularExpressionValidator there's a control named "RegularExpressionValidator" you found this control in toolbox under validator tab. Use that control read link which i posted and to allow only numeric use ValidationExpression="\d+"
Hope my answer help you to solve your problem.
If you are using Web Forms, I suggest that you use CompareValidator. Make sure that you specify the Type attribute of the validator as Double as well as the DataTypeCheck attribute as DataTypeCheck. If you prefer to enable client side validation then assign True to EnableClientScript attribute. I hope this helps...
Zen
精彩评论