Validating an ASP.Net textbox as not empty but allowing whitespace?
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.
- Create a new type of validator that does not Trim() prior to validation - this is the long pole and most time consuming
- Use JavaScript to validate and control the postback yourself (assuming client validation)
- 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.
精彩评论