防止用户在 asp.net 模型验证中的表单输入期间输入空格?
我在 asp.net MVC 网站中使用模型验证。 我想要一个功能来阻止用户在测试框中输入空格并提交表单。
还有其他可用的验证属性,但我找不到任何阻止用户在输入文本框中仅输入空格的验证属性。
我可以为此开发一个自定义属性,但还有另一种称为正则表达式验证器的方法,我认为我可以轻松地使用它来实现此功能。 例如:我们可以设置一个具有正则表达式的属性来验证电子邮件。如果用户输入错误的电子邮件,立即显示电子邮件格式错误的消息。
我想使用相同的,但我不知道如果用户仅输入空格则验证表单输入字段的正则表达式。
请帮我看看这种正则表达式? 谢谢,
I have bee using model validation in asp.net MVC website.
I want to have a functionality to prevent user from entering whitespace in testbox and submit the form.
There are other validation attributes available, but i could not find any validation attribute that prevents user from entering only whitespace in the input textbox.
I could develop a custom attribute for this, but there is another method called regular expression validator which i think i could use easily to achieve this functionality.
For example: We can set an attribute that has a regular expression for validating email. if User enters wrong email, immediately a message is shown that email format is wrong.
I want use the same, but i don't know the regular expresison that validates a form input field if user enters only whitespace.
Please help me with this kind of regular expression?
Thanks,
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
使用正则表达式验证与此模式:
这将只允许非空白。
(更新)
如果您希望用户输入空格但前提是其中有非空格:
Use Regex validation with this pattern:
This will allow only non-white-space.
(Update)
If you want users to enter whitespace but only if there are non-whitespace in there:
这个正则表达式可能有效
This regular expression might work