标题:
一个注册表单验证的js
[打印本页]
作者:
admin
时间:
2008-1-19 23:39
标题:
一个注册表单验证的js
这个脚本对你可能有帮助:
/ _# `: r# u _. a! U8 ~/ W
<script language="javascript">
0 s) H0 u4 ?) o
function IsDigit(cCheck)
6 i5 [; c9 I; ]" W! E- _0 C
{
# p$ o9 z' t( ^$ I% ]& l( p
return (('0'<=cCheck) && (cCheck<='9'));
5 a/ ]/ ?0 _0 H. N5 [
}
) X i" f. J/ A+ _- c4 i
' }2 I* g! T5 x+ s# X) @) `
function IsAlpha(cCheck)
6 a; z7 x4 Q1 P% ]
{
) }6 a( |) A3 h
return ((('a'<=cCheck) && (cCheck<='z')) || (('A'<=cCheck) && (cCheck<='Z')))
' h3 S- D- ~* f% I
}
0 ^- R8 X: U, e% H, _
* ?5 }$ H9 I7 |8 q& b8 s6 z! |
function IsaNull(cCheck)
: l9 j1 ?6 L: ]# ^ }
{
o$ G6 V9 l x& `# v+ ^
return(cCheck != " ")
$ t/ n) g+ ^- A
}
! v9 ]% W1 ]! ]' X/ k
6 k/ ?& W# m4 ?8 c- i8 s9 h1 n
function checkform()
' C, q V4 c* Z+ J5 z- i1 E
{
9 V; S4 Z! w2 f; a& x
id = document.sform1.id.value;
. B' \4 d4 u5 j, F
if (id == "")
, C; o) N0 E: i( R" W+ b
{
0 V& X; b7 V4 v5 h
alert("请输入注册名");
0 Z; E( y+ V3 b4 v
document.sform1.id.focus();
; R& p% w8 C7 n8 r- @
return false;
2 Q. \( F5 x$ }, C+ h' f
}
6 w1 n: @* b' s3 ^2 a
; x9 _+ T i* N n h @
for (nIndex=0; nIndex<id.length; nIndex++)
! j3 n6 k5 [$ t8 Y# v/ \% n7 ]) Y
{
& o# U Y6 a7 S- |
cCheck = id.charAt(nIndex);
/ a' r8 r! t, ?/ P+ J5 d0 Y
if (!(IsDigit(cCheck) || IsAlpha(cCheck) || cCheck=='-' || cCheck=='_' || cCheck=='.'))
6 u: e8 a9 c; a
{
! t( G+ M/ j3 e1 x3 Z; ~3 o/ j
alert("用户名只能使用字母、数字以及-、_和.,并且不能使用中文");
+ u V9 ]5 m1 N( [
document.sform1.id.focus();
" ]) B" Z# Y p
return false;
+ S6 M9 y: [& F- v+ \' D
}
+ {/ J |, B9 b' T8 t
}
% ] q+ N) K( w1 q; [
chineseid = document.sform1.chineseid.value;
* W B3 A' b& U @! ]
if (chineseid == "")
]1 `5 c! o) x9 S" ]" p' G
{
& M% K# o: F5 `3 }5 p& [
alert("请输入中文昵称");
; l3 \8 p, R. x* \9 s( {: }; p8 U& g
document.sform1.chineseid.focus();
9 e% o' q; h$ G3 [: F9 h& C
return false;
, _3 Q2 U) I1 O" [0 `8 A; g
}
; c9 ]' B* I7 N. r$ R# r2 f, e
password = document.sform1.password.value;
$ w% f- _3 @' ], K
if (password == "")
& W1 v- ~5 l* l# l6 V E
{
2 ~/ o6 R4 ^. g+ a
alert("请输入登陆密码");
5 ^0 E5 ~# p# @0 s& z
document.sform1.password.focus();
( M8 {' r* P1 w2 t
return false;
- B# d) u/ h P H% N
}
. n$ w' f( _7 v1 u' H+ ]3 m0 a
password1 = document.sform1.password1.value;
: ^0 ]% R: @; q4 p. i9 L
if (password>password1)
$ `) c* Y0 F. k
{
, N# H) k' g, R, x' m+ Y
alert("重复密码与登陆密码不相同");
, x2 d9 \. q) x+ i" G
document.sform1.password.focus();
# S$ U' v8 N/ ]1 s3 K6 p8 @4 n9 d0 X
document.sform1.password1.focus();
; A+ B" k. K0 ^, W+ W6 \
return false;
- F2 q2 b% `. @; j( C; j
}
, s( A- b( n6 B2 G( p0 A; Z
if (password<password1)
3 p. I2 s4 ]$ ]
{
( f9 t4 Y8 [7 _. n7 Q% v- `
alert("重复密码与登陆密码不相同");
% u0 M: {4 l1 w( j& |5 g8 O7 Y
document.sform1.password.focus();
4 Z, T9 {, S# f/ f Q4 L' o8 e: f
document.sform1.password1.focus();
. P, T* C, X* ]- s
return false;
r0 ]/ a! o7 P# ?# z* g
}
( j! Q" p+ R4 s; @: T
if (document.sform1.email.value == "")
8 d4 I H. J/ z1 C& E+ g' Z
{
' J! R8 C8 j$ @# f) }4 D! X/ Z) D
alert("请输入您的E-MAIL地址");
8 K" O. n% N3 L' k% a! E
document.sform1.email.focus();
7 S, d. H% _; m9 C n$ i2 t
return false;
v9 S0 B* C% N a9 |4 b' Z
}
7 A8 z9 }) S# x
/ d* _, d5 }; x6 e
email=document.sform1.email.value;
. s- v+ r4 z, _$ t. {( n3 u( g
emailerr=0
3 h8 W6 {; r$ ?$ u' |
for (i=0; i<email.length; i++)
( @8 p6 F! y: z
{
. k, P9 |1 J5 H, j7 h' K6 |5 M( C
if ((email.charAt(i) == "@") & (email.length > 5))
6 l" W! y. \2 \( Z
{
8 {: X/ o$ V* G2 {. G. [
emailerr=emailerr+1
' k2 F1 {( \ a8 ^6 w( H
}
: ]# W3 ^6 p3 [8 s" O
}
5 X% e) j. P+ A) x% O
if (emailerr != 1)
2 I0 W2 j) I1 P0 P5 @- L9 p
{
8 |: G- C/ Q( H3 M
alert("请输入正确的E-MAIL地址");
- W: H) d% b/ x! ^0 q4 Y9 J
document.sform1.email.focus();
( L: D2 Y$ j4 A( l: O( S' L
return false;
5 M5 ^% N9 Z, t6 I" D$ m2 m
}
H3 l* L1 @4 g2 Z
1 ]: ? m, @, e$ @# t
if (document.sform1.checkask.value=="")
5 A# `1 a# {4 P
{
* K( m3 e8 ~9 q3 w- G( r9 v, j6 S0 U
alert("密码提示问题不能为空");
: H+ f; H- d0 A6 ?7 w% {5 F
document.sform1.checkask.focus();
) k) U; d0 B. X7 c5 @* O
return false;
% p( O) z0 O, I" u
}
8 @) o' \5 d2 e) j
if (document.sform1.checkans.value=="")
1 b; t8 t! G: l, A5 u& {
{
- M+ B) ]" E5 G" \
alert("您的密码提示问题答案不能为空");
( ], k& m2 K3 a. E. |! C! f9 ?% b
document.sform1.checkans.focus();
% S" V6 o A3 O2 r
return false;
9 g" w* X. ]( c+ U5 X
}
2 {- m- Z! M8 u# h1 Y' D) j
return true;
, C; n. I: m+ w* ]( `* P9 ~' o" N
6 m) V4 ~' t+ R4 G! H' t3 W, I
}
9 |) J1 R1 y$ y, `) p( L
</script>
欢迎光临 捌玖网络工作室 (http://89w.org/)
Powered by Discuz! 7.2