pp_check.js
3.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
<!--
/**
* input check
* which 表单标签名称
**/
function input_check(which)
{
if($('input[name="'+which+'"]').val() == '')
{
if($('input[name="'+which+'"] ~ .err').length == 0)
{
$('input[name="'+which+'"]').after('<span class="err">此信息为必填项</span>');
}
}
else
{
$('input[name="'+which+'"] ~ .err').remove();
}
}
/**
* select check
* which 表单标签名称
**/
function select_check(which)
{
if($(':input[name="'+which+'"]').children('option:selected').val() == '')
{
if($(':input[name="'+which+'"] ~ .err').length == 0)
{
$(':input[name="'+which+'"]').after('<span class="err">此信息为必选项</span>');
}
}
else
{
$(':input[name="'+which+'"] ~ .err').remove();
}
}
/**
* checkbox check
* which 表单标签名称
**/
function checkbox_check(which)
{
if($(':input[name="'+which+'"]:checked').length == 0)
{
if($(':input[name="'+which+'"] ~ .err').length == 0)
{
$(':input[name="'+which+'"]:last').after('<span class="err" style="float:right;">此信息为必选项</span>');
}
}
else
{
$(':input[name="'+which+'"] ~ .err').remove();
}
}
/**
* 座机检测
**/
function valid_telephone(tele) {
var patten = new RegExp(/^(0(10|2[1-3]|[3-9]\d{2}))?[1-9]\d{6,7}$/i);
return patten.test(tele);
}
/**
* 手机检测
**/
function valid_tele(tele) {
var patten = new RegExp(/^1[358]{1}[0123456789]{1}\d{8}$/i);
return patten.test(tele);
}
/**
* 邮箱检测
**/
function valid_email(email) {
var patten = new RegExp(/^[\w-]+(\.[\w-]+)*@([\w-]+\.)+[a-zA-Z]+$/);
return patten.test(email);
}
$(function(){
/* 手机验证 */
$('input[name="tele"]').blur(function(){
var tele=$(this).val();
if(tele=='' || !valid_tele(tele))
{
$(this).next('.dui').remove();
if($(this).next('.err').length==0)
{
$(this).after('<img src="__IMG__cuo.jpg" width="17" height="17" class="err" />');
}
}
else
{
$(this).next('.err').remove();
if($(this).next('.dui').length==0)
{
$(this).after('<img src="__IMG__dui.jpg" width="17" height="17" class="dui" />');
}
}
});
$('form[name="rule"]').submit(function(event){
select_check('catid');
input_check('title');
input_check('name');
if($('.err').length>0)
event.preventDefault();
else
return true;
});
$('form[name="group"]').submit(function(event){
input_check('title');
input_check('name');
checkbox_check('rules[]');
if($('.err').length>0)
event.preventDefault();
else
return true;
});
$('form[name="fenpei"]').submit(function(event){
select_check('uid');
checkbox_check('group_id[]');
if($('.err').length>0)
event.preventDefault();
else
return true;
});
/* 图片尺寸 */
$("#typeid").change(function(){
$('#chicun').remove();
var val=$(this).children('option:selected').val();
$.get('<{:U("getchicun")}>',{'pid':val},function(data){
$('input[name=img]').after('<span style="padding-left:10px; color:#ccc;" id="chicun">尺寸:'+data+'</span>');
});
});
});
-->