我想提出一个EditFor文本框只接受数字 [英] I would like to make an EditFor textbox accept numbers only
本文介绍了我想提出一个EditFor文本框只接受数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的视图模型:
[Required(ErrorMessageResourceType=typeof(Resources.ValidationsResources),
ErrorMessageResourceName = "Required")]
[Range(0, 9999,
ErrorMessageResourceType = typeof(Resources.ValidationsResources),
ErrorMessageResourceName = "SomenteNumeros")]
public Int16 Quantidade { get; set;}
这是我的看法:
<label class="Quantidade">
<span>Quantidade</span>
@Html.EditorFor(model => model.Quantidade)
</label>
但我想阻止在此编辑器的所有单词,只允许数字。
But I want to block all words in this editor and allow only numbers.
我怎样才能做到这一点?
How can I do this?
推荐答案
使用一个普通的前pression,例如
Use a regular expression, e.g.
[RegularExpression("([1-9][0-9]*)", ErrorMessage = "Count must be a natural number")]
public int Count { get; set; }
这篇关于我想提出一个EditFor文本框只接受数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文