返回列表 发帖

一个注册表单验证的js

这个脚本对你可能有帮助:
6 M/ X- q4 A& c: Q' N; g9 I) \, r<script language="javascript">     8 q3 b4 p0 Y9 @/ \
function IsDigit(cCheck)     / J4 E; P" k6 J# ^+ g: X: ?5 T6 _; w5 ]
{     ! I# K, B: H3 M" o4 N
return (('0'<=cCheck) && (cCheck<='9'));     
5 C# K# O. w% ` }     6 L6 J( n9 z9 [" T8 Z9 T
     
) X" H3 _+ D  R/ d# I  @; ofunction IsAlpha(cCheck)     # i: c* e' |- {
{     7 T  i" H, c7 a" S4 m  z6 D
return ((('a'<=cCheck) && (cCheck<='z')) || (('A'<=cCheck) && (cCheck<='Z')))     ) E4 @* ]# ~* r* o
}              
+ b! X  Q. P. q1 U6 A( d" e      
. Q* c. J! ~0 P3 c" Ffunction IsaNull(cCheck)         
9 |/ ]# d* }; _% [" W {          , @$ ^/ ~) g; `9 ~7 d2 K( m
return(cCheck != " ")         
$ U9 g6 S; t4 ~' a4 j' s* r }                              
* c6 }  _- f+ m! |" `      
! q! r1 l' y( F7 t  `& @function checkform()     ) ]" u/ Y9 S& @7 G+ O; ~
{
* g. E0 j% Y, [( S+ Q8 _; j  id = document.sform1.id.value;     
7 S5 x. F$ \) V. A if (id == "")     
7 D% ]: M1 x7 P2 S# f) g: O  {     # G3 y: s7 j% [# Q+ f" R
  alert("请输入注册名");     
! Y9 B$ |( M6 S  document.sform1.id.focus();     
9 W& }; z  ]1 o5 I) B9 L  return false;     9 d2 p. ^" a+ s2 L( q# D
  }     " M" ?1 e  a5 _) m4 G
     / z; y2 X3 Z4 U2 k
for (nIndex=0; nIndex<id.length; nIndex++)     5 Q, ~+ ?* ]+ Z. h
  {     $ U" X! |. B# L8 t1 @+ u
  cCheck = id.charAt(nIndex);     
) @" P3 g' Z. x) F" Y; N& J  if (!(IsDigit(cCheck) || IsAlpha(cCheck) || cCheck=='-' || cCheck=='_' || cCheck=='.'))     
  `; A1 b; s6 `  p, s8 }7 B   {     
1 b3 q* \6 W( c$ \9 r  x, _# L   alert("用户名只能使用字母、数字以及-、_和.,并且不能使用中文");     
( z0 {' J  ^7 T7 f, a" y   document.sform1.id.focus();     
7 m% {3 n- a/ S- A   return false;     ! e4 _. ?$ e- O) ^
   }     2 E9 Z$ T* T, \' N
  } . q. D1 G4 Z1 z, J" p$ Q3 h
  chineseid = document.sform1.chineseid.value;     
$ O/ d$ R. l1 @! R4 U; w" C3 i if (chineseid == "")     
3 Y, I5 C$ j& c) e! a  {     
# A  W) [  O5 h8 f8 d  alert("请输入中文昵称");     - y& i" R# \# v8 x. E; ?3 k' P
  document.sform1.chineseid.focus();     + h! w+ W2 C! l! B% v% b% P3 G& A
  return false;     ) T4 [( w/ g+ X( ~. j+ u
  }    8 X; O. @0 w; m' L
password = document.sform1.password.value;     8 U4 ^, }) E. f2 K, S4 r
if (password == "")     
+ z! W4 m7 y2 B; S- i  {     
6 N+ [' F0 X1 O/ A  alert("请输入登陆密码");     . d( P& ^9 y4 n% W/ r; V9 Q
  document.sform1.password.focus();     ; {  K; }/ ]0 s, E* a
  return false;     
7 E, F. W2 b# B. v. @+ Y  }
# C' [7 s0 p% Y password1 = document.sform1.password1.value;     - b! O1 i0 q! f
if (password>password1)     
% Z4 s; L! B. N- S) ~7 i  {
* e6 P; Q  T  B0 V; J; }* O     alert("重复密码与登陆密码不相同");     
: t, @) b7 q# r. t, x# q  document.sform1.password.focus();
$ d8 Y+ z9 w8 n3 Y. Q                                document.sform1.password1.focus();     ( D# u, i6 N$ }' J5 n' m
  return false;( K) D+ [" C8 [% \4 N$ U' P% e
  }  
/ A5 P% s2 }: Q% Q3 iif (password<password1)     
- b+ Z' z: `" ~( M2 [8 k' ]  {0 J, R0 Y. r# u& z0 U
     alert("重复密码与登陆密码不相同");     
5 u2 A, x# f& V8 u  document.sform1.password.focus();
5 m( @) U+ p; H& ~3 D. d5 T9 v" Y                                document.sform1.password1.focus();     - [% W5 ?* z: `0 Z
  return false;/ G" T- T9 R$ F7 @4 ^, s! k! K% `
  } ' t% X4 O9 Z: F
if (document.sform1.email.value == "")     9 O3 D" }( S* B
  {     
* n/ j7 U! r: Q  alert("请输入您的E-MAIL地址");     
/ B3 U' c* [; q: y& O  document.sform1.email.focus();     
/ H3 U8 k  a, [: w* P  return false;     0 M5 r! j* N3 t# ?/ ~
  }     $ x. s* q: D3 X9 E
      7 o8 Z6 ]4 T- @) k9 O
email=document.sform1.email.value;      ( r) }9 p6 ]. k6 P
emailerr=0     : d1 n: W1 r* b0 u) z0 t/ w+ Q3 Q
for (i=0; i<email.length; i++)     8 `, i/ H! |3 d, t% d5 P1 Q
  {     2 E1 L3 c  c' X: I8 z
  if ((email.charAt(i) == "@") & (email.length > 5))     7 F9 `" `8 `0 Q0 K' b
   {     ! m3 T6 |. ~4 U+ y4 U
     emailerr=emailerr+1     ! Q: v7 y  Q: ?- e! r
   }     + n& P* a& P& M0 o. i
  }     
( w! A  v: C" m if (emailerr != 1)     5 B% E3 w: \- |
  {     
9 M! H- X, e# u1 v  alert("请输入正确的E-MAIL地址");     
9 t+ |+ X- y! b+ }; u  document.sform1.email.focus();     
9 E6 E6 t! N* H9 @5 L  return false;     2 r: C+ Z2 c0 Y: S# Q
  }           
5 ?% k+ V1 i7 x/ T* n& ?0 W/ s  ! R* U4 g2 h8 z* y% k- j' n0 y
if (document.sform1.checkask.value=="") ( n* Z7 h9 \! b
  {
$ \* s8 G8 A5 u1 L' Z6 Y   alert("密码提示问题不能为空");     
2 s1 \! S% g5 z4 O4 N: \# P   document.sform1.checkask.focus();     5 i0 S: R' x( q4 Q2 F6 r7 }( w6 y
   return false;  # ^6 J( p( |- Y  S( k
  }
' ~' a8 d" ~7 Q% \& S if (document.sform1.checkans.value=="") ; p% _- V: i4 |/ n9 A  P
  { " x, K/ p/ N" ]4 z
   alert("您的密码提示问题答案不能为空");
9 ~: W- y4 [3 B: C) X9 h6 r% W  T; d   document.sform1.checkans.focus();     4 J& [  G0 K, n
   return false;  " n3 B9 y: c" q9 l" I) c* ~
  }
" l5 }" H7 W7 @ return true;     
/ C+ T5 |: n; I1 J6 k# x/ c     
) |/ x3 S- _" C5 H3 _} 4 M) ~* q* s) i; y
</script>

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