返回列表 发帖

一个注册表单验证的js

这个脚本对你可能有帮助:7 j" W% x" b! P" b  W
<script language="javascript">     
9 p0 H+ M) {- Pfunction IsDigit(cCheck)     
' _$ U( q6 h. O+ \ {     & A& H0 U0 }: V: a
return (('0'<=cCheck) && (cCheck<='9'));     ) P' I) G1 w( x7 m) l
}     
4 @- y! u) O, p$ C) Z3 e. O- y  Y     
+ [- X% h: p8 R6 v: @: Zfunction IsAlpha(cCheck)     ' h9 C; g- Z4 n0 |  R4 t* o
{     
6 E( `+ }" H* _, P% Q return ((('a'<=cCheck) && (cCheck<='z')) || (('A'<=cCheck) && (cCheck<='Z')))     
6 y: B) h0 F7 i( s' y }              9 C+ Q0 ^8 Q0 L! J% q9 g
      
- F. i2 e' R, d& mfunction IsaNull(cCheck)          6 ^3 `+ X% I! ]
{          ' t* |$ i! v/ {: e/ {5 c
return(cCheck != " ")         
0 \5 t& V2 D" }2 Q2 C }                               . V8 o& F( o1 _
      " {; @# @! `& ~8 }5 ~( i2 D
function checkform()     . {: {/ ~( P, b* J: G0 z2 K9 @/ p
{
1 n  m3 I  d: }! n  id = document.sform1.id.value;       v7 k  S' C, B8 z' t
if (id == "")     6 ^+ ~6 h5 J& k
  {     
% W& U4 h9 H) b/ w9 p" Q. L9 ^  alert("请输入注册名");     
5 _9 q5 w9 b2 q- S" Z  document.sform1.id.focus();     
; s8 X' y' P+ z/ m  return false;     8 `- j5 M2 y: o
  }     
1 j1 b0 F: }: s     
# ^/ r% M0 @% U3 `- q: b* o; R2 k for (nIndex=0; nIndex<id.length; nIndex++)     # w. S" T2 h& M" z! E- ]& G
  {     
; L* e/ |* [' e+ Z" q, f, G% F  cCheck = id.charAt(nIndex);     
  h4 t3 i- N. h9 p  if (!(IsDigit(cCheck) || IsAlpha(cCheck) || cCheck=='-' || cCheck=='_' || cCheck=='.'))     
  _& H8 y5 a/ [   {     9 e* o$ n: D& u; i( S$ l! s
   alert("用户名只能使用字母、数字以及-、_和.,并且不能使用中文");     5 |2 G# }: ~8 a# S  y2 v/ i
   document.sform1.id.focus();     : p$ ~$ [, u0 t
   return false;     7 _! r: D# }, k8 Z8 N! e
   }     . o3 p/ d2 i+ C$ e5 m% f/ u
  }
7 g: o0 c3 E( R; G. O9 K* i  chineseid = document.sform1.chineseid.value;     0 E; ^$ d" G4 g3 O* a
if (chineseid == "")     
( B8 d; `. n8 u  E; y* K  D5 F7 L  {     3 N0 n4 [1 n  e$ e  v0 J; l
  alert("请输入中文昵称");     0 L) U; L% b- [8 w$ `
  document.sform1.chineseid.focus();     
2 D7 T% @( M6 s0 P# @: m  return false;     
. N; a3 V' M, y8 i0 {5 \  }   
. H9 _4 I2 d! e7 \0 k0 ~2 c password = document.sform1.password.value;     $ p# j2 w1 v/ v
if (password == "")     
6 T* K, L- o  S1 `/ k' q8 P  {     ! a# ?) E9 K0 y4 E0 Z; L
  alert("请输入登陆密码");     
2 W, `4 G5 b0 `: n8 `  document.sform1.password.focus();     ! F' E" u; _' k
  return false;     
2 A" J3 s- Y$ `" b6 ~  }
2 G/ R2 A% x; A, | password1 = document.sform1.password1.value;     7 X* L1 x/ H  d# a8 \' T4 n
if (password>password1)     
/ x9 v* V' u1 z" M; ?  {
( g: w! B" P/ y" Y6 U& y     alert("重复密码与登陆密码不相同");     8 h' b9 V9 _' M: @% R7 i
  document.sform1.password.focus(); ) G1 H9 ]2 N! V- y% J
                                document.sform1.password1.focus();     - X# U$ x4 j8 {
  return false;
3 o4 X: B  C5 [* X  }  3 O3 Q, L& j: ~' u: U5 I
if (password<password1)     7 _. H  h+ p0 s: D1 w  C
  {
0 m! ?+ W9 e+ i- H9 ?+ h# T) Z     alert("重复密码与登陆密码不相同");     
! w7 X! r+ l6 b  i3 |  K  document.sform1.password.focus();
/ D1 m9 L! {% v% L" l                                document.sform1.password1.focus();     " v# ^  u" P9 K2 V' G$ B/ |
  return false;1 C* S9 S3 Y; J$ L
  } 4 L2 q8 v6 t0 i3 a3 O% z
if (document.sform1.email.value == "")     ' U7 r6 S. [, X4 H3 E0 L) L! W
  {     3 R6 J, _( t8 C4 V' X/ h; u
  alert("请输入您的E-MAIL地址");     $ F3 i: l' w: k
  document.sform1.email.focus();     
0 N: u3 v8 S, t- }  return false;     8 k6 `5 }  D- d: @0 d& @
  }     
4 A  u% W7 z( H; L$ C      9 z5 p0 q; X, ?& b
email=document.sform1.email.value;      0 M9 p- ?* q* ]1 ^# Q5 R
emailerr=0     / S1 g/ n) b7 W. }" s( U
for (i=0; i<email.length; i++)     % c: |9 ~& t# g0 D# g: ^
  {     4 `5 ~: Y' L! c' X7 j0 Q' B
  if ((email.charAt(i) == "@") & (email.length > 5))     : J( O5 `# {8 D+ V1 w
   {     
* r) i8 u/ r/ c# D     emailerr=emailerr+1     
9 C, q( X1 c' a4 \   }     
( P# X7 n4 L! z+ U9 @8 W  }     
/ M/ Q5 U& b4 J, p: t if (emailerr != 1)     5 j5 k( b9 e$ K/ `% K, k
  {     & P8 P+ s* l6 m8 W+ `4 P' ~1 P
  alert("请输入正确的E-MAIL地址");     
$ |  j, y8 t; [7 N) L; m7 A* G  document.sform1.email.focus();     ! w- {7 T  Z) Y( E0 C" N& g
  return false;     
( F2 b( Y$ ]9 t! n+ l! i8 N  }           
& [1 y; g# a1 H! G2 ~  
% S0 i8 ?9 O5 o if (document.sform1.checkask.value=="")
4 s9 j$ K8 Y2 p: ^) X  { 5 \+ ?6 R0 B8 v$ S# ?
   alert("密码提示问题不能为空");     
$ s! ~' s& t7 P5 L- ]- U   document.sform1.checkask.focus();       }- l; l9 g  l! S" @) u; H
   return false;  2 D' Y9 |8 t- i1 x, S4 I0 a
  }   H8 f* O* S$ W( {# p- ~
if (document.sform1.checkans.value=="") 7 K, L$ ~! ~& J- C# p3 d. e
  {
' J0 q: N% o3 c: i3 ?8 c; v) d   alert("您的密码提示问题答案不能为空");
; k: e- `0 \6 l) t   document.sform1.checkans.focus();     ( H0 _/ t/ J; `; T, J
   return false;  
2 G+ Z  [1 {- W; u$ [* ^  }
9 y3 z4 L/ x( y! e8 @( d; e" @9 d4 S return true;     
; ?, l2 [/ z2 G6 X     . \' E& E6 g& b; q
} 7 n, \/ s) C* d. G/ h  v
</script>

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