制限フォーム入力ボックス特殊文字およびスペースのフィルタ
10400 ワード
コードは次のとおりです.
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
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
html>
<
html
>
<
head
>
<
meta
charset
=
"UTF-8"
>
<
title
> JQuery
title
>
<
link
href
=
"css/style.css"
rel
=
"stylesheet"
>
<
script
src
=
"js/jquery-1.9.1.js"
type
=
"text/javascript"
>
script
>
head
>
<
body
>
<
div
class
=
"box"
>
<
h2
class
=
"h2-caption"
> JQuery
h2
>
<
hr
><
br
>
<
p
> :<
input
id
=
"code"
type
=
"text"
name
=
""
value
=
""
onkeypress
=
"return ValidateSpecialCharacter();"
onblur
=
"validate(this)"
>
p
>
<
p
> :<
input
type
=
"text"
id
=
"dd"
name
=
""
value
=
""
onkeyup
=
"value=value.replace(/\s/g,'')"
>
p
>
div
>
<
script
type
=
"text/javascript"
>
function ValidateSpecialCharacter(){
var code;
if(document.all) { // IE
code = window.event.keyCode;
}else{
code = arguments.callee.caller.arguments[0].which;
}
var character = String.fromCharCode(code);
var txt=new RegExp("[ ,\\`,\\~,\\!,\\@,\#,\\$,\\%,\\^,\\+,\\*,\\&,\\\\,\\/,\\?,\\|,\\:,\\.,\\,\\{,\},\\(,\\),\\'',\\;,\\=,\"]");
//
if(txt.test(character)){
if(document.all){
window.event.returnValue = false;
}else{
arguments.callee.caller.arguments[0].preventDefault();
}
}
}
//
function chineseVaildate(value){
if(value == null || value=="")
return true;
if((/[\u4E00-\u9FA5]+/.test(value))){
return false;
}
return true;
}
function validate(obj){
if(!chineseVaildate(obj.value)){
alert(" ");
}
}
script
>
body
>
html
>
html
>
は の りです.