我需要知道如何添加金额/数字验证[关闭]

问题描述 投票:1回答:2

我需要知道如何添加金额/数量验证。请帮忙。

function validateShowform(amount) {

if (x == "") {
    $("#amountError").css("display", "block");
} else {
    $("#amountError").css("display", "none");
    google.script.run.validateShow(amount);
}

请告诉我如何解决它。

function CheckDecimal(amount)   
{   
var decimal=  /^[-+]?[0-9]+\.[0-9]+$/;   
if(amount.value.match(decimal))   
{   
alert('Correct, try another...')  
return true;  
}  
else  
{   
alert('Wrong...!')  
return false;  
}  
} 
javascript validation google-apps-script google-apps
2个回答
0
投票
function CheckDecimal(amount)   
{   

if(typeof amount === 'number')   
{   
alert('Correct, try another...')  
return true;  
}  
else  
{   
alert('Wrong...!')  
return false;  
}  
} 

您可以尝试typeof运算符来检查它的数字


0
投票

你可以尝试这个,希望它对你有用 -

function CheckDecimal(amount)   
{  
 var val=this.value;
  var valid = /^[1-9]\d*(?:\.\d{0,2})?$/.test(val),
  if(!valid){
    alert('Correct, try another...')  
    return true; 
  }
 else{
 alert('Wrong...!')  
return false; 
 }
}
© www.soinside.com 2019 - 2024. All rights reserved.