禁用文本中的空格 [英] Disable white space in text
本文介绍了禁用文本中的空格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何阻止文本框条目中的空格?
How can I block white space in textbox entries?
我尝试了此操作,但没有用:
I tried this but it is not working:
[RegularExpression(@"/^\s/", ErrorMessage = "white space is not allowed in username")]
public string UserName { get; set; }
'^'取反不应该在文本中留空格,但不允许我输入任何空格字段中的文字。有帮助吗?
'^' negation should not allow white space in text but it does not allow me to enter any text in field. Any help?
推荐答案
使用 \S
(这是对 \s
=非空白字符):
Use \S
(which is negation of \s
= non-whitespace character):
@"^\S+$"
如果允许使用空字符串,请替换 +
和 *
:
If empty string is allowed, replace +
with *
:
@"^\S*$"
这篇关于禁用文本中的空格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文