目標:
如果輸入數據包含任何字母,我不想檢索任何數據。輸入數據驗證過程出錯
問題:
如果我在變量ddd中輸入了數據「23w」,轉換過程在變量currentvalue中可以接受爲「23」。
我不希望它被轉換成數字,如果輸入數據包含 任何字母。
源代碼是在jQuery中寫的,如果可能的話,在jQuery中檢索新的解決方案會很好。
// Fullmetalboy
var ddd = $('#field_hourInput').val();
var currentValue = parseInt(ddd);
// Validating message
if(currentValue <= 0)
{
alert("Value must be positiv");
nonError = false;
}
else if( (isNaN(currentValue)) && (ddd != "") )
{
alert("value must contain numbers");
nonError = false;
}
else if( (isNaN(currentValue)) && (ddd == "") )
{
alert("value must contain value in the textbox");
nonError = false;
}
什麼不正確? – PeeHaa
我喜歡你的「目標」如何開始「我不想要」。 –