返回列表 发帖

一个注册表单验证的js

这个脚本对你可能有帮助:
1 o) T3 g& a, w6 w1 z: H) w, `<script language="javascript">     
. M, `- z5 o8 Q2 H$ @" I4 Mfunction IsDigit(cCheck)     
; ?- }1 ?  y  _/ {  D; L" D+ [* @ {     
; L/ e6 O* q- ]7 j return (('0'<=cCheck) && (cCheck<='9'));     
* ?; a) a" w$ g5 A+ x+ S }     + R& S" M0 T' h* v$ ^+ t  h3 d. q) F
     * _0 V# W, r' Y, ]. p
function IsAlpha(cCheck)     4 N* h- u1 v7 D$ ~- ?/ g
{     7 S* |. ~. N' d" u1 B; P1 P
return ((('a'<=cCheck) && (cCheck<='z')) || (('A'<=cCheck) && (cCheck<='Z')))     " Q- U  F" k" x& E$ C4 Q* M6 T
}              
/ D8 `0 W+ g2 G& @  g+ F      6 @, o& h* B% c
function IsaNull(cCheck)          - U. a: i" L) M+ @1 I
{          ' p' s9 @4 I+ \1 P
return(cCheck != " ")         
/ {( Z' |$ ^) t9 p" }8 Z3 Q1 f) h3 G }                              
" G9 |) q( }" g) h' `: n- ^      
. U  ~3 d$ D) F. B! T) Ffunction checkform()     
- N3 {7 ~8 x5 X1 d) ~{ 5 _/ V. g8 c7 G' T+ f/ \4 O' |
  id = document.sform1.id.value;     
! A( d. n# h* c# |' c if (id == "")     
* a0 f+ [" Z  V" w2 f  {     1 l) Z3 ]' X! p$ C! z& c
  alert("请输入注册名");     
, }* ?) t6 h' N* o. V  document.sform1.id.focus();     
5 B: ]! ?3 s) t( J  return false;     5 s; H  O/ e  _9 J6 C
  }     2 p/ ^1 L4 K' b% @) z
     
. k; f8 I7 Q' Y9 G/ e. [/ Z for (nIndex=0; nIndex<id.length; nIndex++)     ; M3 f- F2 v% u3 z$ m8 s1 r; D
  {     ) ]3 c/ I! j, z9 Z- v3 ]( M+ ~9 R+ V
  cCheck = id.charAt(nIndex);     
8 D1 R( Y2 z: E3 o* D% [0 C* \  if (!(IsDigit(cCheck) || IsAlpha(cCheck) || cCheck=='-' || cCheck=='_' || cCheck=='.'))     - @' Q& ]( J6 q3 M0 v2 _$ F
   {     6 y6 n# {6 S* B& b9 f
   alert("用户名只能使用字母、数字以及-、_和.,并且不能使用中文");     
" e+ D; g- D* g6 _7 M   document.sform1.id.focus();     ( Y8 ~2 Z! V4 G6 g
   return false;     
5 A& Z/ D5 d5 s3 E. m8 u6 X( C   }     
% I* v* q; i$ z  } 1 C+ E8 p, k  A. F
  chineseid = document.sform1.chineseid.value;     " I2 G- m% Q8 ?; B4 s5 s
if (chineseid == "")     
9 w, M6 \- `  f0 x7 H3 B0 \6 b$ J, T  {     : j9 u. ^2 o* x
  alert("请输入中文昵称");     
, z) O; w3 Z1 A8 D2 C  document.sform1.chineseid.focus();     
, x# t- D* y! o6 `  return false;     + a& Q! ^1 Q, N! |) }  K
  }   
/ F" c, w4 }9 V: c password = document.sform1.password.value;     
1 f$ J: Q6 V9 J if (password == "")     " m' j: b! @0 b: z$ Y9 |: W
  {     
4 o+ E  J+ `% g  H$ T$ n( n  alert("请输入登陆密码");     ( f) H9 m/ w, R$ c
  document.sform1.password.focus();     % P9 x4 q  e: r) B5 y9 W
  return false;     6 u1 x9 s: T" G" A) Q6 {
  }
4 ?1 V6 K3 p0 e. E- v) G5 j% _. K. h, F password1 = document.sform1.password1.value;     
) u# ^) _0 s+ G+ _3 d+ N0 J if (password>password1)     
9 p8 ]# h" w/ k  |  {
9 O" t' }+ l5 B  F, Z( {     alert("重复密码与登陆密码不相同");     2 Y6 e3 B% B. `* z
  document.sform1.password.focus(); & C& Y- g7 ^, x5 s  c
                                document.sform1.password1.focus();       m: Y1 N2 ?+ ]7 p. y
  return false;, Y7 a. q$ m' n; O' k! C
  }  
3 w+ Y2 r9 `# e/ c9 I, vif (password<password1)     6 ?6 M7 `2 A5 a# ]4 q; H
  {6 y: D" B/ D/ T! ^3 P
     alert("重复密码与登陆密码不相同");     / b3 D9 n* G* X% }% M8 J) q
  document.sform1.password.focus(); 8 Y( p9 z- [6 z$ s
                                document.sform1.password1.focus();     ) @4 q$ u+ u* @! `& K# A
  return false;& K+ n- s8 T$ L- M% ]
  }
  t! X/ L- K6 Y2 t# q1 l if (document.sform1.email.value == "")     
$ _8 E9 c: H' P8 c* z  {     $ i$ i6 k* _- q; o# r# t! ]
  alert("请输入您的E-MAIL地址");     
! ]) v- l) u# a" ?' A  X  M  document.sform1.email.focus();     , [4 y" y+ |' M, ?9 w/ m
  return false;     
4 Q5 q& i* t& ^* E" n  }     
6 C9 e1 @5 _( u3 m      
8 B3 {$ l/ q' _ email=document.sform1.email.value;      
) ~# b: {0 b$ l  O emailerr=0     
7 `" T; c- i4 p- B* B for (i=0; i<email.length; i++)     
4 ]' N9 H3 ?9 S  {     
  y! n  n; ?, k* r  if ((email.charAt(i) == "@") & (email.length > 5))     + m( c  ~5 g* ^- d! S1 u
   {     
8 ]  r/ I* H/ D2 ?1 v' u# @     emailerr=emailerr+1     
& H, e( K" c1 b8 {% V   }     
5 `; S( t4 @/ R8 }  }     
, g- [  c% g: c+ y6 w2 K% Y( ^ if (emailerr != 1)     
7 p# H! E+ ?2 p0 B0 y7 l& y  {     
$ d; \. @: X- ^! w+ D1 b0 P  alert("请输入正确的E-MAIL地址");     ( Q; ^% |  T$ p
  document.sform1.email.focus();     
( Q' M$ I2 s0 R  return false;     / ?6 W' K1 I& G, G
  }           4 ?/ _8 e  X! s8 l
    N3 E* D. h2 B" Z5 g
if (document.sform1.checkask.value=="") + ~( y+ v: w8 ~" ^% s( y. m3 c
  { - r$ G4 E/ Q2 L- G3 y  O5 \- t6 E
   alert("密码提示问题不能为空");     + I& W" N/ z# y3 G' d
   document.sform1.checkask.focus();     % d+ f( |' T9 j2 D& C, L/ ~( J2 o+ D. U+ X( f
   return false;  
( P5 ]- \3 h! {2 F" C: y) G  } " ~9 y7 T1 c: j  o" X
if (document.sform1.checkans.value=="")
. l: m+ x8 @: {% Y5 ~) m+ i9 N8 ~) D  {
4 b# N, V# A, s8 [   alert("您的密码提示问题答案不能为空"); % i9 E  Y  V6 `) r5 r- k' \; e
   document.sform1.checkans.focus();     
( p4 F0 v- H6 d   return false;  & F3 K' o+ c( |4 u
  }( s2 D2 _0 i! f  o5 N2 Q
return true;     ; V0 s4 @/ l/ b7 l- F9 {6 H. @( M
     
1 A! @" w7 s7 E}
& r# f1 |3 @- o2 p- e& O4 G( ]) z9 @</script>

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