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

一个注册表单验证的js

这个脚本对你可能有帮助:
! v1 X; K- I- j<script language="javascript">     
- ?- V9 ?8 u7 a. O2 G- U( n" Rfunction IsDigit(cCheck)     / V5 A; ?" @% A7 q/ e3 Y" q4 C" K
{     4 j3 e! s) Z; V: \) ]
return (('0'<=cCheck) && (cCheck<='9'));     
- n' a5 B6 o( I, }/ h* G# d& f }     
: q8 s1 ?5 _& D3 o7 V     
% J% q& a# y) @) `6 tfunction IsAlpha(cCheck)     1 O; ^/ _7 d8 b% W2 A1 v
{     $ l) E; ?6 O2 v- f
return ((('a'<=cCheck) && (cCheck<='z')) || (('A'<=cCheck) && (cCheck<='Z')))     
0 T0 o4 u3 A. Y: P( S4 K }              : c# x6 G  S( ?0 k1 U9 I4 _  ^; r/ ?* R% O
      
4 j  w7 B" I, W9 y- [function IsaNull(cCheck)          0 l" T5 Z" j: d
{         
- X2 t  D2 j/ j return(cCheck != " ")         
2 i9 S. Z) }/ w) `" C1 \ }                              
* G+ x4 ^# H: }- @3 E$ W! b      # g) ~  T, M, X$ a3 V4 c+ s0 {# c
function checkform()     
8 U' o, X+ Q: J" G5 T* g{ 8 S6 ^6 S% v$ x2 O; E8 S5 u, l
  id = document.sform1.id.value;     
  |( r7 r- z4 d; |, P# o% k if (id == "")     
6 V) \3 E+ K5 a; o1 T2 A  {     ) C1 f1 N& w5 v% z, H
  alert("请输入注册名");     
6 d2 \+ ~) F0 C( p/ Y0 @  document.sform1.id.focus();     
( K0 {7 ~- L5 c! J$ z- n5 k+ F. u, z  return false;     $ Q5 M; s& }0 e* {3 k4 a, ]
  }       F! y  V  y3 U
     
( ]# P) V" D6 s+ l- O for (nIndex=0; nIndex<id.length; nIndex++)     
" v/ s' E- e: x3 _. o6 P% W  {     / A5 D& C3 \5 r/ b# `" Y% ?4 f
  cCheck = id.charAt(nIndex);     6 O) `3 R. `5 V- U/ c# `) `7 a
  if (!(IsDigit(cCheck) || IsAlpha(cCheck) || cCheck=='-' || cCheck=='_' || cCheck=='.'))     & l2 h( {& ^" F5 \/ z5 A% h
   {     2 m3 ?8 t* [' X5 p' B0 b0 @# @2 Z
   alert("用户名只能使用字母、数字以及-、_和.,并且不能使用中文");     7 ^; ?, J+ ^- A" |" S$ z7 q; x
   document.sform1.id.focus();     / u) {% G: P# _% y: n. Z0 r
   return false;     ' V( \. \# _2 |+ b! B) G% |
   }     5 C+ U* Y% f5 N9 C7 f9 B
  }
0 G, B5 l4 I& j9 P: [# ~  chineseid = document.sform1.chineseid.value;     
" Q- k) J; Q/ ~. z; ^6 Z if (chineseid == "")     0 f) {- x# s4 V) g/ \: L" k) y
  {     
& V7 H3 j% G# X7 v5 U$ |! n! P' H  alert("请输入中文昵称");     
' q0 G: {% i, ^5 B  document.sform1.chineseid.focus();     , C8 N7 @! w( S$ A3 R# h8 i
  return false;     
9 `" V# J3 _; e' w: Y  }    - f4 C% X7 c1 b0 ^
password = document.sform1.password.value;     
6 p5 e( o; P3 J0 F if (password == "")     7 b7 z! X! j% H: ~* {( W/ x
  {     
2 `8 y! W7 N2 q' K! i+ h  alert("请输入登陆密码");     ! \( v" S) m: n/ ^( B, `9 C
  document.sform1.password.focus();     2 F9 |7 ]+ c9 ^- l; Q' @. x; L
  return false;     
% R, Y0 G! v; d  } , ^2 z$ g4 Q' k3 F) E: u
password1 = document.sform1.password1.value;     
/ X7 z" ]% z* ? if (password>password1)     
- e, y  n4 y" G0 }2 E4 D  {' m8 v. [- B: A; B
     alert("重复密码与登陆密码不相同");     
7 T$ H/ p0 K& O- j$ c3 F  document.sform1.password.focus(); 5 K% ^. q! W" n2 D( U3 o
                                document.sform1.password1.focus();     1 H/ Y9 A  t/ s
  return false;
9 [+ B+ G  i- B5 K. P4 \  }  
4 X# `& H/ T! U/ A  y0 Vif (password<password1)     
# A4 a4 n7 f' W! n0 ^  {
7 w0 J. [0 @4 _7 P& i; a- ^3 K     alert("重复密码与登陆密码不相同");     
! B2 ^+ z4 y: ], k  document.sform1.password.focus();
+ G, k8 m2 }* |" }) O  i                                document.sform1.password1.focus();     
6 B% q( w5 L, @4 s) F  return false;
" C( m1 G9 ?( ]# Z! w  }
9 _. D) X8 O) _ if (document.sform1.email.value == "")     
2 C9 O( M9 c( h0 f; q- U, X  {     ; j! |1 W- O" |2 L/ |
  alert("请输入您的E-MAIL地址");     * I) j- K! \' [9 b% G# @
  document.sform1.email.focus();     
+ `/ p: u/ @0 M: y( |  return false;     ' y: a/ s, ]0 ~# o- a
  }     
8 a9 l' H/ t. m) [' t7 Y+ ?      ( Q% R* l' L. l5 k, I
email=document.sform1.email.value;      4 {1 q0 _7 j) K9 j5 S5 x
emailerr=0     
* Y& G4 l9 u7 ?) V4 M/ s1 `! b! B for (i=0; i<email.length; i++)     
: i: \" `4 b7 [) z, p  {     
9 p+ `5 j- r6 J: T6 H6 a# e  if ((email.charAt(i) == "@") & (email.length > 5))     
6 v& `: U( ~4 q: R8 z! j$ I   {     3 Y; ]! q+ N' V
     emailerr=emailerr+1     # G: m# O0 l2 }3 u2 n' c1 _
   }     
! e2 F1 W! _) D' b1 k: l  }     1 i8 M* W, g( n; J) N. U& [( z9 J
if (emailerr != 1)     
7 |0 M& U/ h+ {2 s, S# l) m. J  {     + T! U$ n& A) m8 `9 c
  alert("请输入正确的E-MAIL地址");     & w5 A: C9 Z0 ]3 n+ @; C3 `" k
  document.sform1.email.focus();     
7 Y+ o2 @' K2 l4 {  return false;     
3 Q4 ~! l% \( Y( t" D# H1 m8 N- I1 B  }           
; t- D' Q/ p) ]$ @/ {: O1 g  
6 }( E3 s: ^, M0 n if (document.sform1.checkask.value=="")
( n" V- m! ^4 N' W  {
% G& Z; s$ p9 I! S   alert("密码提示问题不能为空");     
; ?' g* H& G% l9 X1 g( e/ R   document.sform1.checkask.focus();     
# v/ Z, I, B  V; o  t& D   return false;  
: a& g1 C/ R  v# u8 ~% h( v) P  }
" c' g/ m1 v, H if (document.sform1.checkans.value=="") $ [9 o4 b6 `4 y2 s; g' }
  { & M! A9 D* o* u% L% B0 w* ]
   alert("您的密码提示问题答案不能为空"); 9 S3 s4 c1 U# x" }! a( w# q8 Z% q
   document.sform1.checkans.focus();       g1 g" [/ }3 y! `
   return false;  
0 u9 R7 P8 i( y, p  }+ V9 {) p1 G2 P' }8 o. Z7 S
return true;     9 s8 C6 U5 O* u; J; r  a( ~" r9 s
     2 d" Z& {9 l1 Q' G) f; A
} - N  ~. q4 Z3 F# Y
</script>

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