您的位置:首页 > 其它

校验用户名和地址加正则数字

2017-11-23 12:44 183 查看
$scope.savegood=function(){
$scope.tips=false;  //控制错误信息是否显示
$scope.valArr=[];
//商品名  地址   价格
if($scope.gname==undefined||$scope.gname==""){
$scope.valArr.push("用户名不能为空");
}else if(!($scope.gname.length>2 && $scope.gname.length<10)){
$scope.valArr.push("用户名长度在2到10");
}

if($scope.address==undefined || $scope.address==""){
$scope.valArr.push("地址不能为空");
}

//数字   /^\d+$/
if(! /^\d+$/.test($scope.price)){

$scope.valArr.push("价格必须为有效数字");
}

if($scope.valArr.length>0){
$scope.tips=true;
}else{
var g2={
"checked":false,
"id":100,
"gname":$scope.gname,
"address":$scope.address,
"price":$scope.price,
"state":"发货",
"regDate":new Date()
};
//添加到数组
$scope.goods.push(g2);
$scope.showadd=false;
}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐