返回列表 发帖

一个注册表单验证的js

这个脚本对你可能有帮助:
, l0 }! D- W, v<script language="javascript">     
* F+ {$ k4 N  ifunction IsDigit(cCheck)     2 r. V4 L# a1 L* |& L$ ?
{     
2 F6 C! V: W; z return (('0'<=cCheck) && (cCheck<='9'));     ! [+ _# q: e+ K; |( l
}     
3 Q$ L) t( n+ i& `) F& H     
2 K  L0 W8 `3 x3 y% Y# T; W/ |7 yfunction IsAlpha(cCheck)     
7 v5 N" h# d/ B$ d6 U7 \ {     
7 o" Z  K$ M$ Q  s8 S. \ return ((('a'<=cCheck) && (cCheck<='z')) || (('A'<=cCheck) && (cCheck<='Z')))     5 [, b- E) {/ c: A- B* a) x
}              
- M! D4 c- _" u7 x1 f      1 D3 P. }- B1 B% v* V% Z
function IsaNull(cCheck)          : e% d$ l: a  I
{         
1 a4 `( n: g" z7 L3 u& h3 A- x+ X, P return(cCheck != " ")         
* P% y1 \7 o% x- h: A3 H/ ^% Q# _ }                               # R9 {$ M9 ?( d' K) T
      9 ]/ z- l1 U2 k. N% j1 b5 {% a5 ~9 D
function checkform()     0 F+ K- s4 O2 x% K- s
{
8 [# D* M# k" s% Z' |  id = document.sform1.id.value;     
$ W+ V5 ^% U: Q2 F. ] if (id == "")     
5 s1 O: v; s; R! O2 h7 j  {     $ A- y( G% U" q. {6 X: v4 K. M
  alert("请输入注册名");     ; z7 Q9 Q8 `% `- u, X6 I- i' l. l
  document.sform1.id.focus();     5 U8 d' W9 X9 Y% @* p- Y; T
  return false;     . X3 A& L3 v$ Y7 R2 O( M
  }     
5 t. r& r5 x8 Q+ z$ W  }  m     
# m1 g' j4 A- L' f for (nIndex=0; nIndex<id.length; nIndex++)     
6 q/ @" j# i5 J- b3 H6 B2 Q  {     
6 c5 y- v) H+ x1 R  cCheck = id.charAt(nIndex);     6 f% @* ^: l( k
  if (!(IsDigit(cCheck) || IsAlpha(cCheck) || cCheck=='-' || cCheck=='_' || cCheck=='.'))     
7 h. Z( ]7 d: ^3 k7 O   {       q8 I) @  h! O. {3 \* O1 v. H
   alert("用户名只能使用字母、数字以及-、_和.,并且不能使用中文");     
3 w% y9 ]8 T) |9 l5 \   document.sform1.id.focus();     , S( V1 ]/ {) j' ]# T# G- U* u) |
   return false;     
- Z4 }2 O9 L1 v   }     
$ R$ T* P* ]' x  }
9 {, t/ f2 I2 {. v  chineseid = document.sform1.chineseid.value;     # @" s2 m1 A5 g! |; L7 {; c- y
if (chineseid == "")     
( k( Y* g; U) T# y  {     
6 m' _+ _* |5 ]% M* a  alert("请输入中文昵称");     
2 g* i8 ^# }0 X  }* z. K, l1 e8 l9 y. k  document.sform1.chineseid.focus();     % C+ [6 |$ ~4 y) [1 h0 a8 z3 t+ e
  return false;     & `, z4 p; X$ V
  }    + ]: J$ j0 s- [: U6 S
password = document.sform1.password.value;     
1 p. l$ M# n8 v  \ if (password == "")     
* A. j5 X( d! d2 K0 [8 l# t4 ^  {     
6 R; E: [4 i& p  alert("请输入登陆密码");     
5 A/ m$ H6 P: M5 s9 E& |4 N; ^5 d8 ?  document.sform1.password.focus();     
% c& M2 i# Y+ K: Y  b, r  return false;     ( o: |( A1 `# W
  } . v$ @7 _3 Y) G5 r
password1 = document.sform1.password1.value;     5 ~/ r9 G! E' B
if (password>password1)     
0 I9 t6 q4 A( }# B+ v  {; L4 O2 ], G; N  X) u+ X# r
     alert("重复密码与登陆密码不相同");     
4 n. Z: h9 M7 G. f; L  document.sform1.password.focus(); 9 F3 P; g& ^: v4 E. l- d/ B
                                document.sform1.password1.focus();     6 I' @) U5 \# I5 \- p
  return false;5 B, u& m% y+ m1 v* t$ u! L
  }  - R. |4 W/ U5 l9 V9 }, k; ?' Q9 l
if (password<password1)     
* P3 e& E& |6 H3 u! z  {
, O- H' [9 _5 W- x  P- p5 o3 J4 T     alert("重复密码与登陆密码不相同");     3 c& O% u- H0 i$ v* S2 s
  document.sform1.password.focus();
! K/ O2 G5 N" L! c' x+ i                                document.sform1.password1.focus();     7 }( o, \7 f3 Z+ n5 ]7 t& y; t
  return false;
9 `* j* |8 E0 q7 y  }
/ f7 W/ `' ^% G9 u1 C if (document.sform1.email.value == "")     1 V1 d" }; Y1 i7 U9 _
  {     , {) F& S# m4 T. S3 j' ]( M
  alert("请输入您的E-MAIL地址");     
( F: V9 N: H1 j! v! q! n  document.sform1.email.focus();     
2 E/ Z+ T5 V, a& }1 E  return false;     4 J! Q, L" V5 s- m
  }     
: k% E$ a* s7 m' ^      , E! M: N- o) U5 @
email=document.sform1.email.value;        R2 W4 k2 d6 w" |/ o9 f( {; c0 c
emailerr=0     
+ D8 ~+ n1 t" \" _$ t for (i=0; i<email.length; i++)     5 k( k. p" n6 _# b+ ~4 G" b
  {     
& _- P. k$ E8 c; H$ t3 {  if ((email.charAt(i) == "@") & (email.length > 5))     
  E" [2 v8 I1 e8 |   {     3 h6 ~# k- ^0 G" `6 O+ N
     emailerr=emailerr+1     % a# F( P' w: q$ s/ T: T/ D
   }     
  E+ l3 r# b; s( d  }     
' P6 R! g0 \- O( h9 g/ L7 A: B7 N if (emailerr != 1)     . s$ x/ V0 c4 P4 X6 a  U2 E+ t& Y& q
  {     5 G' L. J- u9 x
  alert("请输入正确的E-MAIL地址");     
9 [1 ~2 M, Q- @! ]3 O0 t  document.sform1.email.focus();     
5 g; g: u8 c7 ]% N  return false;     0 e5 A0 I+ u3 p9 P
  }           
/ w/ [' f$ N& p/ P3 [0 x  
  o1 e( a3 c) N. `! D# U if (document.sform1.checkask.value=="")
  n, E* E6 m4 ^1 Y6 a  u  {
2 t9 G8 B- A7 A' A$ q" g* }# a   alert("密码提示问题不能为空");     6 L& B; f" |: m
   document.sform1.checkask.focus();     : R! F$ [) v8 Z1 |; g% d
   return false;  
8 n8 W& m8 _' T( I  }
  n( W) {# x: G4 }. Z7 d" ~) e' E; q if (document.sform1.checkans.value=="")
/ W7 m# Q" j& i: \  { ' T/ e' N% L+ C
   alert("您的密码提示问题答案不能为空"); # p# F/ |) Q" y* _9 S  \
   document.sform1.checkans.focus();     
' F- b: g3 P1 X8 r; o   return false;  
7 O1 t5 h" j2 j6 b; z* [) z  }
5 X, E7 c6 ?$ q' L& R$ Z0 V0 o# F return true;     . b2 M2 c0 V  E0 H7 C1 U
     
  }$ _* t$ I1 \8 l1 R: A} 9 A6 y7 ?6 a* Y7 l* J$ [
</script>

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