开发者

Validating an ASP.Net textbox as not empty but allowing whitespace?

开发者 https://www.devze.com 2023-03-07 22:10 出处:网络
I have an ASP.Net 2.0 textbox which I need to be validated as having some content, but where whitespace alone is valid input.

I have an ASP.Net 2.0 textbox which I need to be validated as having some content, but where whitespace alone is valid input.

A required field validator seems to reject a pure whitespace input as inval开发者_如何学Pythonid. A regular expression validator won't fire at all on empty content.

Is there a simpler way round this than using a custom validator control?


There are a couple of options, neither which use the automagic FUD.

  1. Create a new type of validator that does not Trim() prior to validation - this is the long pole and most time consuming
  2. Use JavaScript to validate and control the postback yourself (assuming client validation)
  3. Server side validate (or use AJAX for validation) - Potential negative is waiting to validate until a postback

I can't think of any other options.

0

精彩评论

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