返回列表 发帖

一个注册表单验证的js

这个脚本对你可能有帮助:5 E; N$ @  f4 {- y
<script language="javascript">     / ]$ f) t+ j6 j
function IsDigit(cCheck)     . Q$ C6 h$ B+ D
{     
2 F. ~0 s8 K( m3 k return (('0'<=cCheck) && (cCheck<='9'));     / ^  x; ]0 |9 ?( `" B
}     
$ R9 ?9 H, U% w4 t* \9 |     9 j- w$ m% @, _
function IsAlpha(cCheck)     
* y7 j: @$ E& [! ^5 U$ K; p/ D5 t {     
6 L  p& u  z# }# [ return ((('a'<=cCheck) && (cCheck<='z')) || (('A'<=cCheck) && (cCheck<='Z')))     
. Y( ?" Z1 M4 b# u1 K4 k! b }              9 t/ }4 k. r6 A! C
      
. ]! S% M4 o1 Lfunction IsaNull(cCheck)          % r& m& q1 Q$ u5 Q$ [
{         
: T- R: P1 R8 {: }: D' ~ return(cCheck != " ")         
) d2 I$ X* M, u: r8 q1 @0 z" n' w/ T }                               5 M# e7 X, N' x4 G8 U4 n, b7 V
      2 o2 R, W# h3 a9 ~  a+ z& ?: Z8 e; ]3 P
function checkform()     % b* d5 m  V) n5 D% J% x- B7 \. X
{ ( B' B( R1 V) a  G* @% J
  id = document.sform1.id.value;     ! H* E5 K- E. v) |2 x
if (id == "")     9 t0 n0 {1 g1 W* O# L: z
  {     
1 x$ e6 M) u: Z  J, J  alert("请输入注册名");     $ R9 e: O1 }8 W6 ~7 u
  document.sform1.id.focus();     7 x; \, d' H7 _  F4 S+ f. [- o% f6 Q
  return false;     
$ P# M6 o) X3 ~) a; i  }     3 Z7 I3 |7 L6 w. Q
     ) d; N% U' i: G' C8 M' K
for (nIndex=0; nIndex<id.length; nIndex++)     9 X2 \& |) q  I8 W
  {     
; B. O5 c( ^/ H5 J1 ]  V  cCheck = id.charAt(nIndex);     
$ E7 A! e: I1 R) l( w% r  r  if (!(IsDigit(cCheck) || IsAlpha(cCheck) || cCheck=='-' || cCheck=='_' || cCheck=='.'))     
, A& s4 ?2 U1 K. x0 A6 P( P& z( z   {     
. j( m1 B  E. Q! s% G9 |   alert("用户名只能使用字母、数字以及-、_和.,并且不能使用中文");     
$ i* X# |9 k, f   document.sform1.id.focus();     ' {' @0 I9 g" e8 [7 |) T
   return false;     : {' ?! @' O" x7 n( h% K" X& |# }
   }     
" T# h6 p$ s+ j; A, k  }   C6 g: b) ^0 U0 K8 h2 [- h
  chineseid = document.sform1.chineseid.value;     
) \% Q6 S% k1 v7 z if (chineseid == "")     
3 b3 t1 a/ Q% f  {     7 F' w8 ?9 a1 Z& J5 }: T
  alert("请输入中文昵称");     
' C9 F/ U7 x& ~$ n  document.sform1.chineseid.focus();     # \% v1 R) G6 h
  return false;     
. c" e* |: P4 u8 }9 ~% z8 W  }    & L. H* |2 T- b2 L6 m. g, F& ?
password = document.sform1.password.value;     , h, x9 y. a4 ~3 p. l! o# L
if (password == "")     ; ~# k3 K. P+ t( ~  V% @9 A7 N
  {     
, A, s4 G2 H. J: x$ `, b- s  alert("请输入登陆密码");     
4 }8 [/ L1 v' o  document.sform1.password.focus();     ! w- j7 [/ L% W4 @7 z: W
  return false;     
9 N/ y; `& x6 W1 e& J( Z# U  }
3 u+ T( [& V/ p! [ password1 = document.sform1.password1.value;     
% s& M# x8 s5 k" l: b( D if (password>password1)     
) V& Y' x$ u; k! S. v5 y$ B; I* }  {) W& b7 C- W% P; [
     alert("重复密码与登陆密码不相同");     - v7 N8 A# `8 P% w- n" T) t
  document.sform1.password.focus(); $ H' `' M1 F9 }" G, k1 h
                                document.sform1.password1.focus();     ( \: V. m0 n/ J& J! Q
  return false;
; R7 e- y! {9 H: f, s* H  }  1 X9 a7 U" i$ w6 m( }
if (password<password1)     " O9 p$ E4 n( O( O* R
  {$ w4 k( g7 d+ L6 E
     alert("重复密码与登陆密码不相同");     6 b8 u8 W' j8 Y, d4 N
  document.sform1.password.focus(); 9 p7 |  y) D' R# x% H6 u: f6 U' J  z
                                document.sform1.password1.focus();     7 t) Z3 ^+ C1 ]) Y4 I# L
  return false;
3 S) I+ \9 K8 p- u  }
/ S, j7 \3 y6 d4 n2 D7 K if (document.sform1.email.value == "")     
/ {1 ]4 u: |4 F: j, ~  {     
+ A! N4 k& p6 t) k- M  alert("请输入您的E-MAIL地址");     
. R( f+ b6 Y2 T  document.sform1.email.focus();     0 ]! F  X+ r0 b6 @' b& q
  return false;     
9 `' F! d( {7 N6 Y  L  g6 `  }     " U3 n- [4 z& }( m' c+ }( T# C( k* k
      
3 U' e2 Q& h: y email=document.sform1.email.value;      
( Z- @4 V1 U0 d" J( `+ q5 o emailerr=0       x) |; g( a# F3 M0 s
for (i=0; i<email.length; i++)     2 ~' ~. x7 R# d1 M9 s2 J8 U
  {     
0 K  c! q, ~* k# L( G; u  if ((email.charAt(i) == "@") & (email.length > 5))     
- d2 X+ v  q" j' H$ B5 Q   {     , R* D0 N% `. R6 W: P% z
     emailerr=emailerr+1     
  k0 f. a( _8 ], q1 \2 b- T   }     
& r& u' C$ s- K9 W7 E  }     7 Y# ]6 j( N8 W: q' r
if (emailerr != 1)     , a( F# _" R3 w
  {     
# W, W, f6 J! U: o3 |; ~+ B  alert("请输入正确的E-MAIL地址");     , i; o6 w3 d0 t; J( ^0 ~
  document.sform1.email.focus();     
# Y  ?; E4 Y5 ~9 P2 _4 E  return false;     
$ d6 K- y7 `- x2 W' N  }           
7 s* w9 }1 p( k+ H- S    x5 x+ `+ N8 R5 C
if (document.sform1.checkask.value=="") # _9 u# ]/ `- P# O2 W9 ^
  { 2 N# ^4 A; W- ^, `! B: E6 X6 W
   alert("密码提示问题不能为空");     
* ]# i, M, Y3 w9 W4 w+ R2 ~   document.sform1.checkask.focus();     
( q$ D3 V+ }6 V, ^# z   return false;  8 u. R" R6 A2 y4 U% V* K; e) Z2 o+ Y
  } 4 K" X% k, M  W  @$ |
if (document.sform1.checkans.value=="") & B; J! j$ y3 m0 {1 {. T# N0 Z
  {
1 @6 `) p# L$ h: z. P   alert("您的密码提示问题答案不能为空"); - f7 {0 E! p* u6 ]- g- O3 H
   document.sform1.checkans.focus();     
) j6 c; _6 \( n* g) Y5 p! H" r   return false;  9 a5 Z) I' T5 `* Z- k, E
  }
) E9 q4 y* `/ b return true;     
) R3 u  G" v; [; a     
( \0 |' C; Q% L0 W, c& `}
+ c( i% }) l8 C, |- W</script>

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