返回列表 发帖

一个注册表单验证的js

这个脚本对你可能有帮助:, H  h9 W& o6 s) t
<script language="javascript">     4 e( D4 {6 }4 o$ b; h5 z  y+ z
function IsDigit(cCheck)     
/ Y# x3 p8 g5 i2 R {     ) z* P( H( B9 E9 i
return (('0'<=cCheck) && (cCheck<='9'));     
/ C) x2 y6 K$ d5 Y }     
  y( I9 T1 q' Y: C2 x! F; M8 R     
; W4 B; J) Z- L" Z8 U8 Bfunction IsAlpha(cCheck)     
& K$ d7 Q" k2 Q8 k$ \2 ^ {     
; }* `6 n- f* X" [, s$ m- ]4 ^ return ((('a'<=cCheck) && (cCheck<='z')) || (('A'<=cCheck) && (cCheck<='Z')))     ' I9 }) i+ r- i/ L( B
}              7 G% z( s$ \1 H" Q
      * Z( g& @+ @0 n2 m
function IsaNull(cCheck)         
8 ^7 a; Q/ l$ l; b {          3 b& s6 P8 \7 u9 N: K: Y" M
return(cCheck != " ")         
  R: D; {  P+ n1 v6 e) a3 K8 n# Z; P }                              
: `4 J+ s: Q6 e6 G& C2 c8 |      
- J  _6 a& V) Z: [/ o& J& vfunction checkform()     3 o5 C7 F, v& ?0 {
{ # V8 I5 }, [- r( D; G
  id = document.sform1.id.value;     
) N- Z1 S$ f! z: m8 y: D if (id == "")     5 Q$ l  k7 a6 k" Q# b& p
  {     / m- r3 D  k1 U# y) U$ x# e6 d
  alert("请输入注册名");     
# I" \1 F; k+ u6 j6 _  document.sform1.id.focus();     ( p6 M6 N" Y+ h! [
  return false;     
/ j! z' |2 G' @- A  }     ' R$ T, Y5 @. {7 [; ^  y
     
3 `6 g0 u: a$ H9 t for (nIndex=0; nIndex<id.length; nIndex++)     
  S+ v* }# \- I: P  {     ! M# R9 d* h- Q. x
  cCheck = id.charAt(nIndex);     
' u2 y/ c% O' }% x! u  if (!(IsDigit(cCheck) || IsAlpha(cCheck) || cCheck=='-' || cCheck=='_' || cCheck=='.'))     & z: b7 S' H- G5 B! n
   {     
; c! S. f+ }6 R! {$ ^% s! Q# }! w+ u   alert("用户名只能使用字母、数字以及-、_和.,并且不能使用中文");     
% e+ x) e- G+ t6 P  `   document.sform1.id.focus();     
+ I( `6 G5 A7 l9 c   return false;     
- [. N6 H' S9 w$ h# G; A   }     
( C/ {* B! _, z  o3 x  } 7 w3 D: D" w0 s* s
  chineseid = document.sform1.chineseid.value;     + B8 x  {- n2 R7 L7 d  ]
if (chineseid == "")     . M4 ^5 m; o7 P/ o* P) B
  {     ! S- s1 w2 H. N1 a* R! p, W7 X" C5 a
  alert("请输入中文昵称");     
7 T: G& m: ]* r# y/ l9 R1 y+ _) }  document.sform1.chineseid.focus();     # Q9 G; Z: n' R
  return false;     1 r7 y5 X/ `  a4 l8 X- m. c; R
  }    7 |% D9 t3 |7 D+ i* C; f
password = document.sform1.password.value;     
  u  `( @" z8 R( H/ r if (password == "")     
! b4 ]- q, z- i7 J  {     
3 |( a+ ~; ?" o- Y& P  alert("请输入登陆密码");     
) ^' Z% W6 D4 A0 x, G: e! B* c7 A  document.sform1.password.focus();     
3 \1 O# `5 l" b8 M; @  return false;       h  o' Q1 B9 y# I9 M7 M
  }
6 @: N& v  V" @  T& g password1 = document.sform1.password1.value;     
; l( W) @! `3 S+ T( `- S if (password>password1)     
. Z9 h. r- N0 g7 K! q, R6 l  {/ {8 d( c6 |. E4 x: k* Z* a
     alert("重复密码与登陆密码不相同");     8 O3 p. X, V, B) }8 H" G
  document.sform1.password.focus();
" N1 x3 U' M2 y                                document.sform1.password1.focus();     
3 R  e- V9 X. Z3 D  V) A" M  return false;
: A& S8 Y: ]) K# w: X, [- F  }  * i! J' o& h& q% Q* Q! D
if (password<password1)     
# d0 v& E5 r6 K. H* D  {" Z0 p/ j( _9 c4 l/ |% P
     alert("重复密码与登陆密码不相同");     7 ^9 P6 ?' k8 k" J6 Z- V
  document.sform1.password.focus(); . l* T  k2 h  o7 A
                                document.sform1.password1.focus();     ) f5 Q1 w# m" `$ B0 e; O
  return false;
# C* c( G1 y% h' X5 m4 O! c  }
7 s  X1 Q, m" l8 e. t9 P if (document.sform1.email.value == "")     7 O9 s. V9 s7 A1 E; Z, e* x$ M
  {       _' x, J  O6 q: S0 p8 a
  alert("请输入您的E-MAIL地址");     
6 j# }& ?" z8 y2 Y  a  document.sform1.email.focus();     
  ]( A- w1 U4 Z  return false;     
6 G6 j& \- p% m3 o  }     2 r+ L- ]4 E( C6 Q9 [
      
' s( V+ v, A& N7 Y  e+ c! o+ Z; b  |0 [ email=document.sform1.email.value;      
; x$ b% S- d" H- c" Z  A emailerr=0     
! ]0 P! e: C3 Q! z5 L for (i=0; i<email.length; i++)     ! A2 K, [) ~. s  R- O! F
  {     
- q; ^5 O! o! m& Q# e  if ((email.charAt(i) == "@") & (email.length > 5))     
, K9 U0 F& T2 O, ~   {     
- {0 j) o. W% J& |8 k     emailerr=emailerr+1     
( f6 Q, S4 `) G6 z$ @8 D9 N/ e   }     0 m0 e$ I! n' o" Y3 z; |
  }     & v' K$ t! X8 [! ?$ C# h
if (emailerr != 1)     
7 t  a/ o. a- r# i  {     ! v( U: c7 P  N' Z$ Q
  alert("请输入正确的E-MAIL地址");     - |& v! V. B9 p- w( [" E- |
  document.sform1.email.focus();     
4 F1 T" M' L* h. X5 O7 ?+ I  return false;     
8 _6 v( U6 P( H3 y$ F6 j1 l  }           . z. A3 b) e( I( D, D# h
  
2 o. h' c8 a$ T, U* b if (document.sform1.checkask.value=="") . \0 m* W9 k' B2 G/ X
  {
9 p8 V- Q$ _- h2 K3 h0 q1 v, S- I   alert("密码提示问题不能为空");     # `6 \9 t/ Q5 ^4 [& t9 ]
   document.sform1.checkask.focus();       h: |* J; I( P- a4 W. x  _  |
   return false;  
; u: `. r0 R7 L3 N5 X  }
, s9 J$ `7 c3 G1 p9 C8 u: w/ P if (document.sform1.checkans.value=="")
. V) t% y0 q- l3 d3 @" r7 ~: \" u  { % ~# ?% @% C+ M6 U( G3 W
   alert("您的密码提示问题答案不能为空");
- N2 y/ d4 H" m+ k" f! ?. @. e  F1 ^   document.sform1.checkans.focus();       D% H* `* G  ^& ^% Y# [! F& c* S' n$ X4 l
   return false;  ! L# g" T3 L8 x5 D6 }$ c6 E3 G
  }) D( c# H3 t+ I+ V, a2 n( G
return true;     
6 G6 v, Z( q* I7 b     , E8 a4 C; t* j+ U9 N3 n
} ! X3 `; ?, ?- v
</script>

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