返回列表 发帖

一个注册表单验证的js

这个脚本对你可能有帮助:* a8 M8 S! {2 D) u% _5 F; I7 G4 c% V
<script language="javascript">     
7 k# Y/ `0 E  C1 U8 Kfunction IsDigit(cCheck)     7 T2 k" f* J' p5 M
{     1 M' \8 y& N2 f/ M& q6 T, t2 w
return (('0'<=cCheck) && (cCheck<='9'));     4 s/ E( s8 e$ x# v
}     
$ i0 {8 ?2 P& i  A2 L     
# I: S& R! F7 ]0 Wfunction IsAlpha(cCheck)     0 {- s7 l7 H- @: d
{     
, o$ o2 g' S& k return ((('a'<=cCheck) && (cCheck<='z')) || (('A'<=cCheck) && (cCheck<='Z')))     % E; j9 o( d6 t1 R/ b- O
}              / z! F9 ^1 `. q( N8 c2 r& O
      ; o$ A) J0 C3 r/ W# ^$ g
function IsaNull(cCheck)         
  X0 a/ D9 V& { {          ; q$ J% q1 r5 k& j$ m) H! N
return(cCheck != " ")         9 t4 P) ~/ _! |8 j* }! Y
}                               / ^+ m7 _0 }/ r. a
      
& s: _8 f' s% Bfunction checkform()     8 r- a4 ^; a* A  ]* V7 D
{ $ F/ z& K1 [  t$ h
  id = document.sform1.id.value;       Z0 M; M5 S0 C. z. _/ J* B
if (id == "")     
: A, L6 J  _+ b4 |  {     3 m' n  `& }: h0 w3 d, r( v& V
  alert("请输入注册名");     
4 v0 h( r$ ?' }! h+ O8 P6 l( W  document.sform1.id.focus();     
0 h% A. y% l8 D7 s% c7 ~  return false;     6 B1 ]( K# X" `6 i
  }     9 K1 _2 ]4 ~% C+ S  {: b
     
  F1 S3 H2 E4 b3 y% X" P for (nIndex=0; nIndex<id.length; nIndex++)       B7 p$ G% m% Y4 m1 {* p
  {     & m( ^, F4 C7 [* q1 l, Q
  cCheck = id.charAt(nIndex);     
5 m  |  a1 ?! z0 t/ W3 @  if (!(IsDigit(cCheck) || IsAlpha(cCheck) || cCheck=='-' || cCheck=='_' || cCheck=='.'))     
3 ]$ K' _$ j) F   {     
$ Q+ S# D* v6 ?6 p% H+ [; L   alert("用户名只能使用字母、数字以及-、_和.,并且不能使用中文");     
" d- x9 t5 `4 @% K. F8 N7 ]   document.sform1.id.focus();     % w2 p! S. I) Y7 a
   return false;     ! R9 I' |1 r: b$ y
   }     
: P+ S1 I) S, n( X% q. ~  }
' S6 U3 D+ c% f: u  chineseid = document.sform1.chineseid.value;     
+ W, r  U, c* k5 ^+ C5 ^. k% G0 H if (chineseid == "")     : g/ e# w# N1 v/ C/ _. k+ Y& k  w
  {     
5 U  K  J0 {# {8 r  alert("请输入中文昵称");     
! e; g1 a( R; t3 ]  document.sform1.chineseid.focus();     
- i/ a. \7 g6 P. Q/ G  return false;     : `9 W- J- `9 V1 E/ s0 e) w. x+ c1 j8 m- l
  }    4 L- J$ a% |$ V+ U, [7 B' |
password = document.sform1.password.value;     
" G. u" P; d! o9 U if (password == "")     
- ~& P+ o) q5 [) O  {     
! I( u  Z- |1 E* u0 I  alert("请输入登陆密码");     
8 d' y! t7 O7 O/ \2 B6 `  document.sform1.password.focus();     
4 f% T. T1 Q4 x8 `' E! _& g1 ^2 Q4 r2 H  return false;     7 P0 P9 M+ H% M6 c1 s, D
  }
% A! ~3 N0 v  c: p. r0 { password1 = document.sform1.password1.value;     9 E& H+ ]6 t& s7 t6 H
if (password>password1)     " ~8 ~+ v8 `$ j, y0 \$ Z
  {
. W% i! d, Z8 c& z  Z     alert("重复密码与登陆密码不相同");     & l  B4 W0 e1 n! P
  document.sform1.password.focus();
1 g# ~- j7 N8 `; c- j3 ]% h                                document.sform1.password1.focus();     
+ b  U' H8 c" y* f; e! V  return false;
! v7 h% n7 {0 p  }  / b& p+ T8 v/ S5 ~# Y
if (password<password1)     # z0 f2 a, U% h' B3 {
  {8 I) w% m. W6 [) y3 G5 b
     alert("重复密码与登陆密码不相同");     
% L% M% o" L& a/ a  document.sform1.password.focus();
6 D) C, v7 W5 [( n2 `                                document.sform1.password1.focus();     $ m% w- p8 J3 k/ v4 I. g
  return false;$ w$ e! p# ]& X$ f
  }
/ J8 b9 K" z+ `/ g; z( `; \- G/ E if (document.sform1.email.value == "")     
! N& g2 \; g. o8 W7 f  {     $ }" J( r. n/ m' d; {6 M
  alert("请输入您的E-MAIL地址");     ! I2 o, `- U& K7 j5 G4 D' I" W5 N; f
  document.sform1.email.focus();     
- L1 J2 T# T8 q/ l& O/ b% Q; P  return false;     
2 D) Z; a, f  c  T: g) K4 S  }     3 m6 _3 ~6 B) @* [& w  h
      ' ~8 b  p+ S  E8 X1 @
email=document.sform1.email.value;      $ w3 o4 g5 ?1 `& r4 O
emailerr=0     
- d6 N" A1 e# N8 c for (i=0; i<email.length; i++)     8 ~% R% J1 l- M
  {     0 m( L1 Q5 z; ?- J! b7 R
  if ((email.charAt(i) == "@") & (email.length > 5))     7 ^0 S' q4 ?3 @  ]; @( i$ x) R: Q
   {     
+ k4 l8 c! L, l/ h     emailerr=emailerr+1     
$ j% t' W; A* D2 }   }     7 ?' |% t" `$ |5 y$ }
  }     : q) h2 G2 N7 ]& y- A/ K
if (emailerr != 1)     
0 @, k8 b3 f0 i$ I  {     6 p0 s' |7 y; N/ C' ~, m1 P) X$ E: b
  alert("请输入正确的E-MAIL地址");     6 C5 j- ?4 A* w$ |6 G  E8 N
  document.sform1.email.focus();     0 h5 l: W! A7 W! o) r" C
  return false;     
9 A9 {9 z. C7 K" L* c  }           
( J: f3 c1 l6 E2 h  . m/ h. B5 m- K5 m4 W# L
if (document.sform1.checkask.value=="") ) t% J. K2 h$ i  Y2 ?  E8 K. L3 m
  { , Z. |# b: {/ B. _- o# I) o" W8 p
   alert("密码提示问题不能为空");     " B6 ]) t2 Q; h2 v) c  A! x
   document.sform1.checkask.focus();     7 l* R/ U, ^# h' L0 k  ?# c( `
   return false;  + n, _" u. k# c4 }$ c* w
  } 1 o2 X; ]: R8 u# f9 Q: [  t
if (document.sform1.checkans.value=="") 2 n% A4 |- I6 |2 }9 t# I
  {
+ ~5 C$ d+ L# E" _/ f   alert("您的密码提示问题答案不能为空"); 2 T/ F5 ?9 k  S4 K
   document.sform1.checkans.focus();     0 N9 y- \; e% T- C5 E  y
   return false;  
5 L+ W1 g; h6 C+ `/ \5 W8 `  }6 G! L# e) f) U0 b' _3 l% @- d
return true;     
$ C+ V: Z  {. t, a/ F2 o7 j     
. j0 v5 u3 {. x9 C) N2 U8 J% |) \}
( r4 s& J5 l$ i; N) J3 v</script>

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