2016-07-22 64 views
-1

有没有什么办法让MVC中的数字文本框具有所有验证功能(不想使用Kendo,因为它有各种验证问题)?Asp.net中的数字文本框MVC

+0

你有没有找[HTML文本框的数字(https://www.google.com/search?q=html%20numeric%20textbox )?这不是mvc特定的。 – Igor

回答

1

您可以用JavaScript验证这样的:

function isNumber(n) { 
    return !isNaN(parseFloat(n)) && isFinite(n); 
} 

here

+0

感谢您的回应,但货币也涉及检查小数,并显示时应使用逗号格式。 Ex 100,000 $ – Reet

+0

对于货币,您可以试试这些库:[money.js](http://openexchangerates.github.io/money.js)或[numeral.js](http://numeraljs.com) – Guilherme

0

你可以试试这个,第三个参数是你Html attributes

@Html.TextBox("Age", null, new {type ="number", min="1" max="5", id="age"}) 
0

你可以设置输入类型设置为数字

@Html.TextBoxFor(model => model.numberProperty, new { @type = "number" })