标题:
一个注册表单验证的js
[打印本页]
作者:
admin
时间:
2008-1-19 23:39
标题:
一个注册表单验证的js
这个脚本对你可能有帮助:
5 `0 |% Z; E+ ~& i! Z
<script language="javascript">
) ~0 A+ ?6 P' P2 t
function IsDigit(cCheck)
( O/ k b0 y' R6 ]4 G
{
3 _" D# }+ T7 X, n- I" U8 x8 c
return (('0'<=cCheck) && (cCheck<='9'));
9 K% P- \- U0 o) D2 E; E
}
: R4 X- t9 L$ Q9 D
3 I+ y' q" k+ D0 Q
function IsAlpha(cCheck)
A K/ y6 O! d9 o/ `, V
{
& f! @$ G8 o( S- z6 N1 B: l
return ((('a'<=cCheck) && (cCheck<='z')) || (('A'<=cCheck) && (cCheck<='Z')))
( Z5 y9 r% g7 k5 b
}
5 ~7 w4 U) G6 d
2 L$ u7 I ?* ~9 L
function IsaNull(cCheck)
7 q9 ?/ w: k) L% G
{
2 r3 t2 H8 ` N; V+ m, d- C' t
return(cCheck != " ")
( o: g, c; c) o0 r9 o0 O% M# K+ |
}
' {! Z4 y* |5 X8 B& n
7 I5 m" S8 x8 g8 G- `5 Q+ a. H
function checkform()
9 I9 P* R3 x. ^4 J" a M# C3 a) ]+ R
{
, }, Y9 o5 K/ B) T: |* c3 U. ~5 \
id = document.sform1.id.value;
5 Q4 I/ O" [5 h8 c
if (id == "")
7 W4 o9 R/ B. t5 ~$ b9 ]4 O0 K
{
4 g6 d( Y3 r# ~: p% @/ s9 Q
alert("请输入注册名");
, L1 M) y( Y* ^3 H1 s. Z
document.sform1.id.focus();
3 H4 L K% T: ^. F7 X
return false;
* D9 ?8 U- u: v
}
! f# A U$ s& r! i2 ]3 s
# x, n$ D. R( K5 O( G/ ^# a/ z
for (nIndex=0; nIndex<id.length; nIndex++)
: ]( r. j1 ]6 V$ B7 O5 ~
{
/ F6 ?" `1 ?+ c; H1 C+ s
cCheck = id.charAt(nIndex);
1 V+ m: F% E7 K( {
if (!(IsDigit(cCheck) || IsAlpha(cCheck) || cCheck=='-' || cCheck=='_' || cCheck=='.'))
# Q: t. D9 E. Y! c. Z
{
" m4 s- `: j1 x! s8 V4 U. O
alert("用户名只能使用字母、数字以及-、_和.,并且不能使用中文");
$ {' w7 t: Y" d
document.sform1.id.focus();
: m. M0 H. i# C6 P
return false;
% M% p) g; [2 {5 a/ | p Y- W
}
9 }" D- m( Y' a( p+ x9 ~- @
}
( K0 F- m" |" a O( b) z$ I
chineseid = document.sform1.chineseid.value;
; A% M) C7 ~# _$ j% a( U
if (chineseid == "")
- {/ v0 V) g% w" `7 ~% C0 U; a9 P v9 w
{
7 W9 A& G- ]! r0 E
alert("请输入中文昵称");
' l O& Z% I4 R" x2 j/ U
document.sform1.chineseid.focus();
/ ?' s. k3 N( Y1 z- {$ N# \
return false;
( h/ f! ^0 B. {8 S1 E$ g3 T
}
) G! P0 d4 F7 E* c1 t
password = document.sform1.password.value;
& W) l5 ` L# v& J/ l* s
if (password == "")
8 B: s4 z2 q# V5 i7 Q
{
% \7 c1 T+ C& Q
alert("请输入登陆密码");
7 s/ g, w# ]* Q! ?2 D
document.sform1.password.focus();
+ g) C6 C9 v. A# F9 S8 N
return false;
- t) r9 Y! ^# j$ c9 V
}
+ ]: c. ]% P' a5 h9 R d6 X
password1 = document.sform1.password1.value;
: b) Y: \. g1 C% ?0 z
if (password>password1)
' y9 @( ?5 K# U) g% ]- ?3 K& b1 F
{
0 h- a7 }+ g' C7 S$ L6 ^
alert("重复密码与登陆密码不相同");
3 K b( d$ y+ |- E: ^' a1 o! u
document.sform1.password.focus();
" t0 C- ]2 _4 T2 ^0 g: E3 u
document.sform1.password1.focus();
0 ?; H) o G1 Q) l2 |* z
return false;
- e* W. V, M3 T, n) U$ X# Q
}
- M$ K5 M7 b& z6 W
if (password<password1)
1 C$ B0 U6 N: w& Z1 D
{
( K# w1 g1 b: S7 V5 C
alert("重复密码与登陆密码不相同");
# C' ^: O7 u6 m: V9 d ?( B
document.sform1.password.focus();
' R$ }8 V. y; r% }$ o8 j* M
document.sform1.password1.focus();
|! ]( X& |4 G: K: F0 n- d8 @
return false;
9 W h X: E) Y: }2 O: K
}
) l7 M) v C. {+ Y( g
if (document.sform1.email.value == "")
6 K, W7 N `) U- ~! | C
{
* n! B; j9 B( N# a7 N
alert("请输入您的E-MAIL地址");
c, J2 q; h$ z, p9 ]
document.sform1.email.focus();
' L0 `5 i1 M* W' P. U; m3 W, P( `8 O$ O
return false;
, ]: {7 [3 ~2 {# @/ q
}
/ t- c% `8 x" A8 f5 t3 X" a* M
' `$ ^9 ^5 f9 k/ q4 o% W% ?
email=document.sform1.email.value;
& u9 \ i8 J$ u2 J
emailerr=0
. T& l8 o. D: P: K: ^1 X
for (i=0; i<email.length; i++)
! ^& F0 j: N+ l' L* j+ [) |/ G
{
/ Y0 ?9 x! k4 G9 D3 L$ m
if ((email.charAt(i) == "@") & (email.length > 5))
' c7 {* [" h/ ?& ~$ m
{
& l0 R, H" e% o- J* k! r+ k
emailerr=emailerr+1
7 R, h+ {1 P, h( e) a
}
, I% u. N$ l, u5 _* `
}
, b3 N% i) ~$ `" E( f; s
if (emailerr != 1)
7 L" Z/ u A N1 i/ x: \
{
6 _" @- h: {' Q R4 P; C
alert("请输入正确的E-MAIL地址");
' }9 i: b( Z- |/ p# X: {* U
document.sform1.email.focus();
+ I1 p4 Y, ]4 | L# M5 w _
return false;
9 @+ |: V7 L& \
}
* }7 l) a0 {" Y5 i& p) ^( p
0 E4 ]! T* h; O
if (document.sform1.checkask.value=="")
, a- V3 B0 a B) X0 P
{
$ Y. h% Y: r' l# F6 J- C8 ?# P
alert("密码提示问题不能为空");
1 q7 F1 W& z q% ^$ x# F6 Z7 [
document.sform1.checkask.focus();
3 I! A$ R$ a+ [4 e \( x8 @
return false;
; H' ^, ?+ Z5 S/ q# v
}
1 S/ E2 j! j: Z" k- L
if (document.sform1.checkans.value=="")
) |+ p* H' D a, R7 L9 g
{
, r( O: c+ t6 f4 B" S' A9 D
alert("您的密码提示问题答案不能为空");
5 C4 s- A% f( p6 Z" K
document.sform1.checkans.focus();
9 i; x: V/ Y, Z; p
return false;
5 T6 s5 L& W7 _. R
}
$ [' e1 A/ v3 y6 l
return true;
0 J* Q. ~; j \8 I
5 J* j0 n; j: _6 [3 k
}
9 X5 N" d2 u3 w2 ?( h
</script>
欢迎光临 捌玖网络工作室 (http://89w.org/)
Powered by Discuz! 7.2