开发者

Validate Numeric TextBox Entries Asp.Net

开发者 https://www.devze.com 2023-04-06 18:17 出处:网络
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 t

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

0

精彩评论

暂无评论...
验证码 换一张
取 消