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

一个注册表单验证的js

这个脚本对你可能有帮助:
$ y- R7 Q. [$ w; Q<script language="javascript">     * s- O% i! K7 Y# w
function IsDigit(cCheck)     
% [3 p% y6 `- j$ a% x: K  K$ H. n4 x6 K {     
7 R1 m% e, l0 g" C0 r return (('0'<=cCheck) && (cCheck<='9'));     ) ?. C6 Y2 {* N# d3 G
}     
4 C0 A1 ^/ F' @* o7 A- r9 C     
7 o: M: [( g3 G/ I6 [4 d2 U0 `( cfunction IsAlpha(cCheck)     ) o! i; t! D# o2 x, H+ `- A
{     
4 r7 x, J: d- ]% @: q5 A+ N return ((('a'<=cCheck) && (cCheck<='z')) || (('A'<=cCheck) && (cCheck<='Z')))     & o+ S: O  H/ }/ K, j2 w! F
}              - s4 L; Y+ i% K# {
      
  L2 Q* u. Q; a, o- z# \function IsaNull(cCheck)          / K( d: U% m! B& g
{         
8 J0 A8 v/ @4 F; T. A$ W# _+ V return(cCheck != " ")         / C  @* C7 ^2 k' K- E2 C8 `8 Q
}                              
. ^& z" W: |4 M  n, J+ O      ! g1 z0 ^4 f/ A% ^3 l
function checkform()     0 H% k/ x8 ]% \9 L* S
{   _, Y; I, p! t/ ]6 w
  id = document.sform1.id.value;     + f7 D# ?( F9 @( @$ g4 h9 I
if (id == "")     
: f6 k; M, H, c9 o5 f/ Y7 o  {     ! b# A3 A0 {; D4 r) D% f
  alert("请输入注册名");     % C1 Q9 x! b9 c( X
  document.sform1.id.focus();     . b; i5 |; W7 p, b9 b" `
  return false;     # v0 f: T, a; |8 ^
  }     
8 d* d+ z% ?: O/ Q( Q6 q     
- q/ O: `+ d/ C) D5 _ for (nIndex=0; nIndex<id.length; nIndex++)     , y1 Y! P% X) {- G1 p
  {     
  o; h/ k) l+ C% \$ |  cCheck = id.charAt(nIndex);     & S! G  y9 y+ q# B" O
  if (!(IsDigit(cCheck) || IsAlpha(cCheck) || cCheck=='-' || cCheck=='_' || cCheck=='.'))     ) E; f3 M* E  f8 j7 L; _+ ]' }7 X
   {     2 n( F' F7 e, j
   alert("用户名只能使用字母、数字以及-、_和.,并且不能使用中文");     7 o6 Q% k( l# z4 u3 i
   document.sform1.id.focus();     
/ n6 M0 S" X& R% A   return false;     
4 j: ~$ W9 V) g4 ^   }     
" _5 Y! N: y& m/ Z  i5 i$ @  } 6 m2 v1 g' q+ l
  chineseid = document.sform1.chineseid.value;     9 m' g! F, Z4 E* J
if (chineseid == "")     2 G+ X0 s( ~& L
  {     , L5 D  p+ R$ W: {
  alert("请输入中文昵称");     
3 u* ^) H/ c7 [; w7 \) M, g7 g  document.sform1.chineseid.focus();     
' i: ]+ b5 m3 w  return false;     ' O; L, b6 |+ a' h
  }   
- H$ [) I  C- H password = document.sform1.password.value;     * a, w) Z; \2 \5 j; a
if (password == "")     
$ S6 [# g. r4 i. `- ?  {     9 m9 \7 h2 J$ w0 M: V# V  o
  alert("请输入登陆密码");     
0 A' U7 K- u8 p; V3 W* `  document.sform1.password.focus();     - Y$ ]. x$ P5 v' V' _
  return false;     
% P. F4 K5 W+ {8 y$ d' \8 ]2 E  Z  }   X& F4 i" s1 O3 E' y8 A
password1 = document.sform1.password1.value;     
4 w0 R& u; P+ w: ], z if (password>password1)     
4 x7 W+ T; g0 [( y  {
* Z. [' k9 p4 X  o: |* t& ?     alert("重复密码与登陆密码不相同");     $ z. E: Z9 l5 \1 q
  document.sform1.password.focus();
7 Z' E3 f/ r( q( C: T0 ~                                document.sform1.password1.focus();     0 k& k2 _6 w1 n* _6 x/ J
  return false;
. X: J$ m$ M2 k3 \7 h( Q  }  
; y0 O8 z( a' c9 {if (password<password1)     . u) `1 d% ]8 I; a& B) g
  {0 n7 f* ^% W1 N. ]
     alert("重复密码与登陆密码不相同");     
2 k' f, x) Z) B7 ~$ _# Q9 S! [  document.sform1.password.focus();
7 Z. u' t$ ]. q                                document.sform1.password1.focus();     & {9 l( T8 r+ N- x) N+ Y' n  A! Z5 Z
  return false;
3 U8 |0 |# r( g9 y  } , c2 X5 @; n; e; b
if (document.sform1.email.value == "")     4 j' p4 |" V: T5 F% s2 `* C+ |! ]
  {     
2 b) K& L5 v8 V5 `' K  alert("请输入您的E-MAIL地址");     7 }/ V  d3 T  A+ K2 U2 r/ I, V
  document.sform1.email.focus();     & I2 U' f9 t2 _5 I
  return false;     
, n4 P4 v& m5 C  p  }     ; I8 o4 t6 k0 }$ J$ s
      6 x$ P; W$ h* ^& g9 b  r( w. E
email=document.sform1.email.value;      
, P0 H. @: K# w& S) T emailerr=0     
) @% O* Q, Y0 v  Z for (i=0; i<email.length; i++)     7 ]5 ?" |4 Z# U7 W6 b0 ~
  {     ; q1 V* V' d3 O! A+ U1 V4 y
  if ((email.charAt(i) == "@") & (email.length > 5))     
0 t+ M( H5 f* ]2 `$ O   {     
+ O5 f" Q1 t7 `' ^  o- o     emailerr=emailerr+1     
4 B! n3 a3 R+ |. F6 [" M   }     
5 c6 O# C, z1 R, b* v3 Z+ Y  }     
* P' q' l+ M1 _$ A if (emailerr != 1)     
2 q7 D+ I5 W* Z- ]" ~  {     
- v! U' P# E+ R% {/ m$ Q4 t3 ^  alert("请输入正确的E-MAIL地址");     ' V; Q& T/ k2 {  ~
  document.sform1.email.focus();     
0 |/ K) c7 T; C* p$ S/ Y4 H2 y  return false;     
" q) t& c- L+ u4 ~6 I9 ^$ ^4 H  }           
! W( p- |0 T( s1 {& i) p2 i6 \) B, p  4 i( w6 F0 [, w- _; r. i; ^4 N* @* d
if (document.sform1.checkask.value=="") 6 m/ k2 V' A2 L
  {
. q1 J, o! O; S; s/ g   alert("密码提示问题不能为空");     
: k, H$ q* x" \   document.sform1.checkask.focus();     
7 z+ G' N$ r0 R1 W: v   return false;  ' K& w+ s' z, y/ a& E
  }
5 Z# e9 k$ ?4 |' E9 o5 Q$ q+ Q9 j if (document.sform1.checkans.value=="") 3 \; B* l: \( q8 |8 B' g9 S( Y
  { + H! `* G6 G7 _; y6 c
   alert("您的密码提示问题答案不能为空");
0 I+ J, F( S1 |5 g" U   document.sform1.checkans.focus();     
1 u7 |1 ^. v9 Q/ T   return false;  
3 r, Y! n* `' c7 J  }6 B( Q9 o4 i3 t9 A4 D4 H/ r: f1 J
return true;     
8 c7 D- A/ u$ Y     
( Q7 ^9 T6 G* D, x% i: j}
; h4 x$ ~' R) D' g% ?& Z$ h</script>

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