检查用户输入的一段代码

//检查用户输入,不符合规则不允许提交查询---by wangguan 2012-03-26
                                        function checkInput() {
                                            var input = document.getElementById('userlist');
                                            if(!input) {
                                                return false;
                                            }
                                            var userlist = input.value, p = /^(?:[\u4E00-\u9FA5\w]+(?:,[\u4E00-\u9FA5\w]+)*)?$/g, //必须是以英文逗号分割的用户名,默认为用户名为字母数字下划线或中文,首尾不能为任何特殊符号
                                            m = '';
                                            if(( m = p.exec(userlist, 'g')) != null)
                                                return true;
                                            alert('输入格式不正确,格式为xxx[,xxx,xxx]');
                                            return false;

                                        }

posted on 2012-03-27 11:56  argb  阅读(209)  评论(0编辑  收藏  举报

导航