判断是否为空是否有敏感词,是否有匹配项

本文介绍了一个使用JavaScript进行表单验证的过程,包括姓名、年龄等字段的输入检查,并实现了数据保存和查询功能。通过正则表达式验证年龄格式正确性,确保数据的有效性和一致性。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

//点击保存按钮
                $scope.save = function(){
                    var i = $scope.datas.length;+1
                    $scope.tips = false;//控制错误信息是否显示
                    $scope.cw = [];//放错误信息的数组
                    if($scope.name == undefined ||$scope.name == null){
                        $scope.cw.push("姓名不能为空");
                        alert("姓名不能为空");
                        return;
                    }
                    if(!/^\d+$/.test($scope.age)){
                        $scope.cw.push("年龄格式错误");
                        alert("年龄格式错误");
                        return;
                    }
                    if($scope.cw.length>0){
                        $scope.tips = true;
                    }else{
                        var data2 = {
                            id:i++,
                            name:$scope.name,
                            age:$scope.age,
                            pinyin:$scope.pinyin,
                            job:$scope.job,
                            system:"删除"
                        };
                        $scope.datas.push(data2);//把数组放入原始数组中
                        $scope.isShow = false;//让添加页不显示
                    }

//查询按钮
                $scope.sel = function(){
                    if($scope.selName == null){//如果为空提示
                        alert("不能为空");
                    }else{
                        if($scope.selName.match("王")){
                            alert("有敏感词汇");
                        }else{
                            var filter = $filter("filter");
                            var shu = filter($scope.datas,{name:$scope.selName});
                            if(shu.length == 0){
                                alert("未找到内容");
                            }else{
                                $scope.datas = shu;
                            }
                        }
                    }
                }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值