2016-07-22 69 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" })