input_chk.js
5.86 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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
//入力必須チェック
function hissu_chk(pstrKomoku,pstrValue) {
strTarget = pstrValue.replace(/[ ]/g, ""); //スペースカット
if (strTarget=="") {
alert(pstrKomoku + "が入力されていません")
return false;
}
}
//スクリプトチェック
function script_chk(pstrKomoku,pstrValue){
strTarget = pstrValue.replace(/[ ]/g, ""); //スペースカット
data=strTarget.match(/[<,>]/g); //パターンマッチ
if (data) {
alert(pstrKomoku + "の入力に不正な文字が含まれています")
return false;
}
}
//カナチェック
function kana_chk(pstrKomoku,pstrValue) {
data = pstrValue.match(/[^ア-ン,"ー","ヴ","ァ","ィ","ゥ","ェ","ォ","ャ","ュ","ョ","ヮ","ヰ","ヱ"]/g);
if (data) {
alert(pstrKomoku + "の入力は全角カナを入力してください");
return false;
}
}
//全角チェック
function zen_chk(pstrKomoku,pstrValue) {
var basic_len=("あ".length);
for (i=0; i<pstrValue.length; i=i+basic_len){
strCheck=pstrValue.charAt(i);
if ((strCheck >="!" && strCheck <="~")||(strCheck >= "。" && strCheck <= "゚")){
alert(pstrKomoku + "の入力は全て全角文字です\n" + "全角文字を入力してください");
return false;
}
}
}
//英数字チェック
function eisu_chk(pstrKomoku,pstrValue) {
eisudata=pstrValue.match(/[^abcdefghijklmnopqrstuvwxyz0123456789]/g);
if (eisudata) {
alert(pstrKomoku + "の入力は全て半角英数文字です\n" + "半角英数文字を入力してください");
return false;
}
}
//英字チェック
function eiji_chk(pstrKomoku,pstrValue) {
strTarget = pstrValue.replace(/[ ]/g, "");
eijidata=strTarget.match(/[^a-z]/i);
if (eijidata) {
alert(pstrKomoku + "の入力は全て半角英字です\n" + "半角英字を入力してください");
return false;
}
}
//数値チェック
function suchi_chk(pstrKomoku,pstrValue) {
suchidata=pstrValue.match(/[^0-9]/g); //パターンマッチ
if (suchidata) {
alert(pstrKomoku + "の入力は全て半角数字です\n" + "半角数字を入力してください");
return false;
}
}
//電話番号チェック
function tel_chk(pstrKomoku,pstrValueSigai,pstrValueSinai,pstrValueKyoku) {
strValueSigai = "" + pstrValueSigai
strValueSinai = "" + pstrValueSinai
strValueKyoku = "" + pstrValueKyoku
if (strValueSigai + strValueSinai + strValueKyoku != "") {
if(strValueSigai=="" || strValueSinai=="" || strValueKyoku==""){ //いずれかの入力なし
alert(pstrKomoku + "の入力が不完全です");
return false;
}
}
if (strValueSigai != "") {
if (suchi_chk(pstrKomoku,strValueSigai)==false) { //数値チェック
return false;
}
}
if (strValueSinai != "") {
if (suchi_chk(pstrKomoku,strValueSinai)==false) { //数値チェック
return false;
}
}
if (strValueKyoku != "") {
if (suchi_chk(pstrKomoku,strValueKyoku)==false) { //数値チェック
return false;
}
}
}
//郵便番号チェック
function yuubin_chk(pstrMae,pstrAto) {
strMae = "" + pstrMae.replace(/[ ]/g, ""); //スペースカット
strAto = "" + pstrAto.replace(/[ ]/g, ""); //スペースカット
if (strMae != "") {
if (strMae.length != "3"){
alert("郵便番号の入力が不正です");
return false;
}
if (suchi_chk("郵便番号",strMae)==false) {
return false;
}
}
if (strAto != "") {
if (strAto.length != "4"){
alert("郵便番号の入力が不正です");
return false;
}
if (strMae == "") { //後ろのみ入力あり
alert("郵便番号の入力が不正です");
return false;
}
if (suchi_chk("郵便番号",strAto)==false) {
return false;
}
}
}
//メールアドレスチェック
function mailadr_chk(pacount,pdomain) {
stracount = "" + pacount
strdomain = "" + pdomain
if (stracount + strdomain != "") {
if(stracount=="" || strdomain==""){ //いずれかの入力なし
alert("メールアドレスの入力が不正です");
return false;
}
}
acountdata=pacount.match(/[^A-Za-z0-9\-._.?.!.#.$.%.&.`.+.-.^.{.}]/g);
domaindata=pdomain.match(/[^A-Za-z0-9\-._.?.!.#.$.%.&.`.+.-.^.{.}]/g);
if (acountdata || domaindata) {
alert("メールアドレスの入力が不正です");
return false;
}
}
//メールアドレスチェック
function mailadr_chk2(pacount) {
stracount = "" + pacount
if (stracount != "") {
if(stracount==""){ //入力なし
alert("メールアドレスの入力が不正です");
return false;
}
}
acountdata=pacount.match(/[^A-Za-z0-9\-\/._.?.!.#.$.%.&.`.+.-.^.{.}]/g);
if (acountdata) {
alert("メールアドレスの入力が不正です");
return false;
}
}
//チェックボックスチェック
function chkbox_chk(pstrKomoku,pobjChkbox,pintKosuu) {
chkCnt = 0;
for(i=0;i<=pintKosuu;i++){
if (pobjchkbox[i].checked) {
chkCnt++;
}
}
if (chkCnt==0) {
alert(pstrKomoku + "は1つ以上チェックしてください");
return false;
}
}
//URLチェック
function url_chk(pstrValue) {
data=pstrValue.match(/http:\/\//);
if (!data) {
alert("URLの入力が不正です");
return false;
}
}
//日付チェック
function date_chk(pstrYear,pstrMonth,pstrDay) {
if ((pstrMonth == "") && (pstrDay != "")){
alert("日付を正しく入力してください");
return false;
}
if ((pstrMonth != "") && (pstrDay == "")){
alert("日付を正しく入力してください");
return false;
}
if ((pstrYear.length != 4) && (pstrMonth != "") && (pstrDay != "")){
alert("日付を正しく入力してください");
return false;
}
if ((pstrYear.length == 4) && (pstrMonth == "") && (pstrDay == "")){
alert("日付を正しく入力してください");
return false;
}
if ((pstrMonth == 4) || (pstrMonth == 6) || (pstrMonth == 9) || (pstrMonth == 11)) {
if (pstrDay == 31){
alert("日付を正しく入力してください");
return false;
}
}
if (pstrMonth == 2){
if (pstrDay == 31) {
alert("日付を正しく入力してください");
return false;
}
if (pstrDay == 30) {
alert("日付を正しく入力してください");
return false;
}
if (pstrDay == 29) {
intData1 = pstrYear % 4;
intData2 = pstrYear % 100;
intData3 = pstrYear % 400;
if (((intData1 == 0) && (intData2 != 0)) || (intData3 == 0)){
}
else{
alert("日付を正しく入力してください");
return false;
}
}
}
}