获得本站免费赞助空间请点这里
返回列表 发帖

一个注册表单验证的js

这个脚本对你可能有帮助:
4 [3 S, E. Y7 a( L; V4 d+ }<script language="javascript">     
& h8 g" t1 c8 l8 |function IsDigit(cCheck)     " l4 Q: M9 v# p! B. Q' D6 s
{     
) S% U0 N7 o# Z return (('0'<=cCheck) && (cCheck<='9'));     
( u& Z( k: ?7 ~: Y6 ~ }     
& c2 j# K- q" k. f8 ^     - _+ r9 {$ Z2 K: ^3 e& \5 ^
function IsAlpha(cCheck)     7 x( g1 b6 m% r1 u; `( T% K& d2 }
{     
, b4 u- [& x8 \0 [4 I return ((('a'<=cCheck) && (cCheck<='z')) || (('A'<=cCheck) && (cCheck<='Z')))     
6 m% @3 Y2 U% k* q }              
* M0 V' H* i2 s: k8 e      
( m4 t2 W' a4 i% s& Nfunction IsaNull(cCheck)            u" q" {5 {0 s+ o6 U
{          & \& r- \& u! S" r5 M. `
return(cCheck != " ")         ; x# {" t9 j7 m* c' o. P; z
}                               1 n  r' A# _* [
      
# O) N7 t' J. K8 m2 n, mfunction checkform()     
9 y& w" _  p9 d, N9 N{
3 @$ g2 t1 w# T  ~- o  id = document.sform1.id.value;     ! S2 E: N3 P2 S5 S/ O; `
if (id == "")     " K7 F1 Y: k4 K; _1 a
  {     
7 u* ?4 ?& W" x6 ?. F% l* H  alert("请输入注册名");     & g6 X: f; f6 u0 U" I
  document.sform1.id.focus();     % ]6 C; _8 s+ |
  return false;     ' p9 _1 `( l% ]
  }     ( I. I- W. ^5 Q
     / m  k% D% n9 c& z( [
for (nIndex=0; nIndex<id.length; nIndex++)     , r" D) _% J; t4 G
  {     
" V. U" K0 ], m$ L  }  cCheck = id.charAt(nIndex);     
) y8 s3 ]8 O) p0 W5 `# R% A  if (!(IsDigit(cCheck) || IsAlpha(cCheck) || cCheck=='-' || cCheck=='_' || cCheck=='.'))     
* {& [% }( `; B- o   {     $ P; B- x9 C( V7 V5 @) T
   alert("用户名只能使用字母、数字以及-、_和.,并且不能使用中文");     ( {  `- |' R9 R* t. ~
   document.sform1.id.focus();     0 j1 I8 o6 ~/ b! L3 ]7 `0 c
   return false;     
% e9 _1 O0 q8 @# Q6 ]! V9 N+ H   }     , ^! J! a7 t9 _  W& t& C% Y
  }
% |9 }' {; x9 a) V( ~6 X$ q. W  chineseid = document.sform1.chineseid.value;     : W& ]) [, G7 r/ \, y. v: S
if (chineseid == "")     
: S6 E5 N9 B# A9 @; ?) R  {     / j- j$ g6 }% C  U8 S: z6 ]. p% E: V
  alert("请输入中文昵称");     
2 n2 v; Z# Y) u, p  document.sform1.chineseid.focus();     ) U6 T! j, r( ?9 g
  return false;     $ V3 r7 m$ f: X, R7 @" I+ ^
  }    / G4 k5 m/ y$ q) x  P
password = document.sform1.password.value;     0 E8 G  e5 {# @) V9 p5 _% s! n0 H5 u3 _
if (password == "")     
) J- V" ^% b; `0 h: h; ^# W  {     
5 k0 m: N$ C# ^$ u$ Z0 y  alert("请输入登陆密码");     
1 r5 g4 ]! @$ c  document.sform1.password.focus();     
# x" a' S  X5 L: O% a7 W  return false;     
2 e% G7 h% U. k* h  }
. g! f' R( l6 \1 C$ @. l& {. @" e) h password1 = document.sform1.password1.value;     9 _* B% X1 c( r9 X! W  W
if (password>password1)     0 d0 L" e& Y( C4 R" K
  {" T4 i' M: e5 I1 e0 W
     alert("重复密码与登陆密码不相同");     % ~3 X: Y5 A$ g6 A
  document.sform1.password.focus(); & p4 j7 b* E% J# D, j4 B, F4 m
                                document.sform1.password1.focus();     1 J  h( h$ v$ f. B3 p1 g3 b. {
  return false;
3 e/ x' e, U& Q' U  I  }  ( m6 |4 f3 l* ^% c
if (password<password1)     
  a% ?0 @- D5 a+ S: x) N: t  U  {7 {" `/ K* g, g" j7 N
     alert("重复密码与登陆密码不相同");     2 z& p4 }( ]4 I1 g
  document.sform1.password.focus();
* E, _! c! z) X' }& s                                document.sform1.password1.focus();     # @" L' ^4 R7 {8 `! K
  return false;: K, y7 K* k5 K; m3 v
  } ( C- ^$ |# w& M  m' p- c
if (document.sform1.email.value == "")     
" o! ~8 ~( a* X9 z4 c5 x  {     
# l( G, ]9 G5 _# E' Y  alert("请输入您的E-MAIL地址");     
. [+ x; j8 c3 u( @4 [, b6 n7 U! G( j  document.sform1.email.focus();     $ W8 s" g3 E8 F: j5 ]
  return false;     
* J$ {& g3 `& x2 G  }     , a4 p0 ]! d! }2 v
      
' }- P; n7 ~; V8 C- l% f' u email=document.sform1.email.value;      ( X6 k! H: n' l: m: f/ ^- }
emailerr=0     , [0 q& c% N: Z$ ]! T+ S
for (i=0; i<email.length; i++)     
7 {0 w1 f) b; P( V! Q5 X/ u  {     , d/ J5 B$ N' p0 n1 G
  if ((email.charAt(i) == "@") & (email.length > 5))     
+ e$ q- _; j( U7 x2 M   {     
# f9 ?- G' j, @1 I3 X     emailerr=emailerr+1     8 E  g& L; |5 a8 H0 }
   }     
4 Q, f2 c; w- {+ g- b  ]  }     $ e) S. P& ?6 @0 v% w  ?: u
if (emailerr != 1)     
! m) j1 p, a9 N/ x& p  {     
7 X8 F2 Q# I+ q7 L; L4 ^  alert("请输入正确的E-MAIL地址");     
: @$ g7 G- z7 M) H1 W9 W- h6 d. L  document.sform1.email.focus();     
' M5 L& F! y) P: ?& U8 A  return false;       C. n. Q( b' F2 R! W  U! J
  }           9 I1 a/ R* n0 e! h. g& @. h
  " C# p1 {# `) D1 |5 f2 q1 E
if (document.sform1.checkask.value=="") 8 f, {- u5 ]1 I( u# ~8 `7 k
  {
3 V9 @! [; ^  ^# F- E) U   alert("密码提示问题不能为空");     . W) \/ ]# [4 _
   document.sform1.checkask.focus();     & ]% K* |/ j' ]: Q5 H; A+ @! N
   return false;  6 C4 Z- @% w  n
  }
4 B" K2 E& y% }, m" U7 H; c8 o3 Q7 v if (document.sform1.checkans.value=="")
2 g* G8 H. R5 g' D* m& d  {
$ A. L+ x! X* m# N5 ^& \   alert("您的密码提示问题答案不能为空"); ; b; o" d6 N- O& C& o$ v
   document.sform1.checkans.focus();     9 R# i* }5 x! Z* |6 o, o
   return false;  
( U! D4 [' g* ?: }% ^  }
; v4 b' P4 W& j/ Q# i' t! N return true;     
% Y# {% R  h; m5 J4 P     8 ^' Q  W; w8 M( n  |9 @
}
1 r% a( C+ Z; D& ?' j& B5 }/ ^7 p</script>

返回列表
【捌玖网络】已经运行: