返回列表 发帖

一个注册表单验证的js

这个脚本对你可能有帮助:
8 A8 z9 s: Z. ]<script language="javascript">     
7 z# [5 {1 {* I2 X' |3 F1 ufunction IsDigit(cCheck)     
1 G0 a2 t4 d* H2 r! Z9 M {     
; J; c" s. f( H  m& b7 z return (('0'<=cCheck) && (cCheck<='9'));     
* F. d1 S; p7 m8 T3 ^2 ? }     . d+ S5 u, T- C) ?: U( H! Q
     
& X) L+ ~5 `+ y& _2 s* `' |/ Ffunction IsAlpha(cCheck)     3 D6 v8 E$ P& X2 ~" X6 B; e7 W
{     4 m% _, s: T. e& B) B# G+ P  S
return ((('a'<=cCheck) && (cCheck<='z')) || (('A'<=cCheck) && (cCheck<='Z')))     $ ?4 g" m) ]6 b. v# G
}              
( P7 L9 q: u- t! J7 I4 k      
0 |' ?, C! y& B( Xfunction IsaNull(cCheck)          - p. H6 R" `2 p, b, r! d
{         
9 ^/ R7 N: H# Q' V8 t6 [# T return(cCheck != " ")         9 _* T$ z. ]5 d, C! N5 U
}                               / ~5 L4 i9 t5 _/ ~3 O
      / _  G( t+ l# q0 }4 q4 ?- X& E
function checkform()     ' B& Z9 w( e* h" S9 x
{ . g2 q5 b, C& b9 h7 q* O) R
  id = document.sform1.id.value;     ; w* [) ~2 |+ U% Y* f5 F
if (id == "")     
' K  [( Y7 T& k6 U- m  {     - H* {! w$ w% h; a7 B( Z
  alert("请输入注册名");     
: q: ^! ^: ~  d  document.sform1.id.focus();     4 n9 `; Y7 L4 a& u" Q* u
  return false;     5 c  T9 `1 m; B7 M! x" x4 H
  }     
. M2 s8 ~$ H4 W# k. b     3 ~8 p8 D" s, L" @. w; K! I# F6 y  {
for (nIndex=0; nIndex<id.length; nIndex++)     
$ {6 C5 l4 C9 h" u3 n  {     
& Y9 [' b6 c) V. e* x/ J) t1 n  cCheck = id.charAt(nIndex);     
0 j4 z: V0 x4 R: _# X  if (!(IsDigit(cCheck) || IsAlpha(cCheck) || cCheck=='-' || cCheck=='_' || cCheck=='.'))     1 i7 Q! O6 I* X( R
   {     
4 }% Z' S$ h; F/ s   alert("用户名只能使用字母、数字以及-、_和.,并且不能使用中文");     
& S( |  g+ Z! X6 K- a! a- t   document.sform1.id.focus();     0 U, F" j" c* g/ L* z
   return false;     8 _/ T+ E5 Y. M" m. b0 g5 I. D
   }     + i+ F- A5 E, W6 }7 \
  } 1 T  I& o) x0 f! q9 S  }
  chineseid = document.sform1.chineseid.value;     7 a) k' W* y# |: M5 ^7 b
if (chineseid == "")     ( u* a" g8 o7 B- r% B
  {     
; s0 y# H6 @/ x% {# {) V  alert("请输入中文昵称");     0 L% ~; {% v  v
  document.sform1.chineseid.focus();     . G6 u' l2 h  d* z+ I
  return false;     0 F0 s  W2 b% Q8 o3 d2 P' e+ m
  }    % D, P# l7 T) N" J& }1 W
password = document.sform1.password.value;     : g6 Q9 R" l% F, C0 v2 V( \
if (password == "")     
  y) E- D- i% y7 M  {     ( e; M$ t3 h' G( B- l( n+ ^
  alert("请输入登陆密码");     
- V. w7 w0 ?1 g! w% T+ Y  document.sform1.password.focus();     
9 G1 _. o+ H, Y5 Y1 e/ n  return false;     
1 D5 |$ R. t* f8 F7 I" |  } # b6 a# y3 S0 A* u5 |5 x
password1 = document.sform1.password1.value;     0 i9 I4 [9 c; o$ U9 ~
if (password>password1)     
( ?2 n* e3 p' U' d8 X  {# S' Y! P5 R; ~8 L- M# ?
     alert("重复密码与登陆密码不相同");     
4 g- b3 c8 D+ g6 t, Z" c8 q  document.sform1.password.focus();
3 O! M  B7 z% l# h3 Q                                document.sform1.password1.focus();     0 d2 l" n0 _: a
  return false;! }$ ]( ~1 u: w
  }  % |* ~) _6 @" X# |9 P
if (password<password1)     3 y6 O5 v7 Q# I5 Y! q! D  a
  {6 b! ^$ Y/ M' w9 P, K: A' c8 b
     alert("重复密码与登陆密码不相同");     
' J; Y1 a; a6 m  y  document.sform1.password.focus();
( t' @  Y# [, w1 v- Q  p* \                                document.sform1.password1.focus();     
, l) N. [- z! `+ H' ]+ V! k; V  return false;( D" \- _0 u- N) @3 g! q
  }
' ]/ o& k0 o% D* v- d if (document.sform1.email.value == "")     
2 w9 J" `% n- V  {     
4 Q4 W: a8 F8 W/ k7 l) h; R+ s  alert("请输入您的E-MAIL地址");     
* r4 U4 t2 C; ^! b  document.sform1.email.focus();     
, J3 L2 P8 |5 i9 F* u4 J) k4 c3 M  return false;     
& G- f7 U, l. {  }     6 i* U* k* R% A* |
      ) h5 ?) r9 x' t3 d/ x  u2 ]
email=document.sform1.email.value;      ( c: H5 ^: a& v" y' |- N0 R2 e
emailerr=0     
3 D, u0 D+ e) o8 h/ p) U1 r for (i=0; i<email.length; i++)     
4 [1 J4 L  z0 ~5 h7 {9 W+ G* W$ J) h  {     7 h4 x' I8 q' m* F) p, m5 Q
  if ((email.charAt(i) == "@") & (email.length > 5))     ' l' y6 I4 K. a8 B5 A
   {     ( x, Q& a5 g3 H: A/ M7 y6 G
     emailerr=emailerr+1     " O" q. X( A% Y& ?7 u4 l
   }     ' C% G" d9 b' y6 m
  }     7 L- M$ @6 e' ?
if (emailerr != 1)     
- Z3 D* y" M7 d" x* J4 z  {     
  B4 C/ n- f9 [3 u9 t; T/ s. z. z2 k  alert("请输入正确的E-MAIL地址");     
* E8 ]  _5 V" Q" v  document.sform1.email.focus();     
: J# J/ ^! U3 n% T$ {  return false;     
) c: N- `6 _1 f# o2 ^& p  }           3 ~) n' Z, Q& x+ J0 N
  / x0 X4 J. n* g% K: c2 S. N
if (document.sform1.checkask.value=="") / M& A9 a9 t" g2 y% M
  {
, L1 A0 ]: Q' e* X, E# A, Z% K0 `   alert("密码提示问题不能为空");     
/ S0 \( I8 s' T& ?   document.sform1.checkask.focus();     + u0 n% {1 E, L4 t  n- x  m
   return false;  % \# N% m: k4 _3 m7 ^" R4 ~0 X
  }
: C4 D/ A8 c# @, j$ y if (document.sform1.checkans.value=="")
" F6 c! ^  J! F, ?' w7 D  {
. q' R3 ?( u- [   alert("您的密码提示问题答案不能为空"); 5 _# {  r- u# ~
   document.sform1.checkans.focus();     
( L! X* S: L' S; s. t   return false;  - O3 F5 w0 `# C. ^7 u8 n
  }3 p) l1 d6 V9 [
return true;     
# ?) `: I6 i  x' _; B% L     
7 U! }3 q% p- \" r7 v}
& X, Y5 r! N$ L/ ?</script>

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