返回列表 发帖

一个注册表单验证的js

这个脚本对你可能有帮助:
$ ~( _9 e1 q3 R<script language="javascript">     4 g) h3 F/ x5 b0 n2 L  X
function IsDigit(cCheck)     8 ^& p- F" ~  R4 E( `$ l5 U$ G
{     
1 z6 u( ?* v$ ]4 N9 o return (('0'<=cCheck) && (cCheck<='9'));     
- ]5 E# ]2 Z2 `. G }     1 U. g& B! b% I: Q8 F
     
1 g* z! q; S# z4 n% r  Afunction IsAlpha(cCheck)     ; ^- R2 |7 m+ u/ y# _
{     
! V0 E+ u0 `- x3 E  ~ return ((('a'<=cCheck) && (cCheck<='z')) || (('A'<=cCheck) && (cCheck<='Z')))     
8 O2 ?: l( ?- m  y& i1 |: p. ~4 O* f }              
( ]* x" d, m: T! {& d' ^      8 @( V9 J) C8 T$ |
function IsaNull(cCheck)          9 y: E' n" j4 R( r" a6 D, A' E
{          3 E) w$ c% Z) R
return(cCheck != " ")         
$ ^- p( V% B6 ?6 @" K( n9 F }                              
+ |( {: f( ]- J% m- [( y& D      
* `% @$ d4 A: afunction checkform()     
6 B9 d, D! @! z% v{ + {( Q7 s6 U' Q/ H& Y
  id = document.sform1.id.value;     
5 @3 {2 M- y! z" V% Y3 @1 `) V- J if (id == "")     9 Y6 w% X4 }5 O) Y7 G$ ]- ]- x
  {     ' c7 z! ]9 c9 ^$ r4 P
  alert("请输入注册名");     
* c- T& Y: k$ ^: q; D  document.sform1.id.focus();     ) t3 S  f2 v9 Y& \
  return false;     9 R2 f& L6 _) d
  }     3 ~( g- d7 k8 ]6 u3 B
     
; T* d( T* ], ]3 O3 f6 d7 Q for (nIndex=0; nIndex<id.length; nIndex++)     
. _  S7 z9 P1 D7 V+ |1 X, S. J  {     2 F% V0 P, Z8 A- u6 V1 j' c6 P6 `
  cCheck = id.charAt(nIndex);     " I' _  N  b! @0 g" Z
  if (!(IsDigit(cCheck) || IsAlpha(cCheck) || cCheck=='-' || cCheck=='_' || cCheck=='.'))     5 B7 R6 k. H- s6 E- C
   {     & {4 L! t  N6 Y0 e" m$ ]) x
   alert("用户名只能使用字母、数字以及-、_和.,并且不能使用中文");     4 k9 x6 O! J! K  W+ {
   document.sform1.id.focus();     6 h% {7 ]5 t9 U0 Y* y' @' H
   return false;     
: c9 D& y0 O" q' e7 {% o   }     ' q! @& I, e4 r  m, K% X
  } ! i$ ?: a6 ?; X1 V+ t2 f
  chineseid = document.sform1.chineseid.value;     
! m4 M! p0 y& R. ~8 ^- a( N! k if (chineseid == "")     4 g: C% B& F" q- m- J# J! a/ u) u8 b
  {     
2 ?' ]# ?' W5 A; N  _; s. {  alert("请输入中文昵称");       O4 z: ]! Q/ _/ H) }5 l5 \/ K
  document.sform1.chineseid.focus();     
0 Z) M8 R6 _  e  return false;     0 j. ?1 L+ }% g. p' ~2 Q
  }    5 V1 b+ J: I5 N) j
password = document.sform1.password.value;     
) u% D' S# _8 V5 J2 Q if (password == "")     / R/ o7 t9 ~4 ~, }4 U
  {     
7 c% U  y# `7 l8 `; _  alert("请输入登陆密码");     
1 i6 Q; ~7 N1 D2 f; ^" H  document.sform1.password.focus();     2 c+ k: }6 {: w9 V
  return false;     " Y$ i# H4 Y/ Z6 @  O& C
  }
. v6 v( n& e9 ^6 J  v$ j3 k, a password1 = document.sform1.password1.value;     
$ l* A" q4 ]3 h4 G4 B5 k7 c8 g if (password>password1)     
( F+ f" j: P* m9 W; Q3 i  {+ P8 \* }; k0 q
     alert("重复密码与登陆密码不相同");     
! [3 y1 Q" M0 Q9 h  T/ U  document.sform1.password.focus();
8 U- _2 S8 |/ n8 p' P. f                                document.sform1.password1.focus();     . k8 s% G3 l# n: @
  return false;+ s6 H( z8 x2 ^5 v# t4 }
  }  1 J7 K9 A8 `5 k
if (password<password1)     , S  x- |- S2 `4 [7 M
  {) C# G4 R8 d% M: j
     alert("重复密码与登陆密码不相同");     
4 W+ \! C2 ~2 D9 h2 n7 j  document.sform1.password.focus();
8 H7 `9 L! @, X% \( F5 J8 I' a                                document.sform1.password1.focus();     8 F4 n" Z  p- t( g
  return false;7 \8 u7 @& R" Y! R; E# I. I
  }
  v0 y% j! H9 Y% b/ a5 V if (document.sform1.email.value == "")     
( t0 r1 M5 K0 a# V  L5 A  {     , L# k% k/ h" ^8 N' ^1 E
  alert("请输入您的E-MAIL地址");     
7 V; a2 e6 V4 S; H2 t  document.sform1.email.focus();     " p, p6 K& H7 Q
  return false;     
$ n3 A  C) O8 d- o% d  }     
; `4 v$ F$ z% B      
, r( i5 r1 m  l* H& @ email=document.sform1.email.value;      9 L0 v5 D2 G! H  t: B# X
emailerr=0     ' ~+ E- s  F; p+ p2 Q; h
for (i=0; i<email.length; i++)     ! d' ^- o& h$ i. j+ K& i
  {     
, d- I+ v3 k  N. D6 b3 F  if ((email.charAt(i) == "@") & (email.length > 5))     
$ I% ~" o% c* G3 \8 b  i   {     
4 m; o' x% a6 [! Z1 z     emailerr=emailerr+1     
9 g7 k$ R+ z8 g9 E- d# J   }     - r4 U# ^  z2 ?5 t" L
  }     " Y' ^4 B# e$ M/ z# R' S
if (emailerr != 1)     
" z  f; o  ?4 O: b  {     8 ^5 O0 k/ G9 q4 z! ]
  alert("请输入正确的E-MAIL地址");     
; B4 q/ B5 S) d/ Z) V) w  document.sform1.email.focus();     
: S) ~; a, g$ k/ y! w1 j/ V& k% C  return false;     3 |! V& K) v# i' [9 K! v
  }           , j# V  \) e7 f6 y2 D- y
  1 ?- D+ _, e" t6 n! ?
if (document.sform1.checkask.value=="") * s8 P/ Y- A& Y5 D; \% D8 O
  { & P- M  V( E2 Q3 y# Y; m1 i
   alert("密码提示问题不能为空");     % ?' H4 e3 T. D6 r2 T9 k1 G& B
   document.sform1.checkask.focus();     
. V4 k( J; }/ J5 j+ l   return false;  
2 o1 p/ p/ R8 c/ b7 @' `  } ' Y- R! z0 E. {+ u
if (document.sform1.checkans.value=="")
: m( G. ?# u( u  {
" e8 d0 y- B  I- |9 v  E2 l   alert("您的密码提示问题答案不能为空"); " R" @  }. t" U, ~, p: \9 b- i
   document.sform1.checkans.focus();     6 D' C1 c" Y  Q6 a' @
   return false;  
4 s6 v5 ~% Y' ?  }
, w! r, v) F3 H4 V return true;     9 a9 |6 z8 e. R0 h! r  t: T( i4 A
     
2 e/ t; m& n* b$ {0 w} - d1 Q( A6 i" |. j
</script>

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