返回列表 发帖

一个注册表单验证的js

这个脚本对你可能有帮助:  L5 _3 O2 R* A3 U
<script language="javascript">     , U" `; m6 `7 f0 \
function IsDigit(cCheck)     8 Y! q+ i" }6 d) S" t. {% v6 W
{     
/ w9 f6 G6 c1 E, m. N5 T return (('0'<=cCheck) && (cCheck<='9'));     ) c8 p) b: E0 @% O7 K5 K$ o: a% a8 Q
}     
# E9 E" a& x- A     + R  _% l+ L+ I! P$ w3 U
function IsAlpha(cCheck)     
$ _: G+ _8 S3 `' y6 t! Z" n+ F {     $ p0 h  f- i3 y* e9 j
return ((('a'<=cCheck) && (cCheck<='z')) || (('A'<=cCheck) && (cCheck<='Z')))     
& M/ [) z2 G4 p" Q8 o }              : T9 F" ^! m" Q6 t. p$ _# X5 l9 ^# ^
      4 o, E/ p, _) t; |
function IsaNull(cCheck)         
+ r4 M6 E* ?0 K8 s {         
: P) s. A, ^* e1 J; G- u return(cCheck != " ")         " F1 B8 ^! ^2 [; @+ W
}                              
/ [" U% |( S$ u$ t$ H      $ u, v* W6 p4 e' ?( d  c
function checkform()     + a8 _4 p6 y. |. `" j, K7 X! R
{
8 [$ Z4 h3 W6 J7 Z* |* T( R& \  id = document.sform1.id.value;     ! ]0 a, G0 B) ^8 F) h
if (id == "")     ( |) a* I# G# c5 h3 }" W; j3 E* ?
  {     
! j# t+ A' s/ g5 n  alert("请输入注册名");     & @# K3 i. p0 h
  document.sform1.id.focus();     : a' C5 `' \0 {5 V0 M5 v; V) q
  return false;     , Q" @0 x2 z5 R6 s, a1 ^  o$ E% k5 l
  }     
) q. [' e- W9 K( n7 C6 F; b     $ c/ p7 q3 C5 u4 t/ s' _. x' J
for (nIndex=0; nIndex<id.length; nIndex++)     
- n# I  l5 ?2 Z: H  {     
  M$ d7 t' R7 H, Z8 K! C  cCheck = id.charAt(nIndex);     9 `( u. t1 C$ \6 W
  if (!(IsDigit(cCheck) || IsAlpha(cCheck) || cCheck=='-' || cCheck=='_' || cCheck=='.'))     
0 [  L, j+ @' g5 |   {     
. B& w# k9 M( M* M! I   alert("用户名只能使用字母、数字以及-、_和.,并且不能使用中文");     9 j# [$ J3 \9 C7 w$ [: F
   document.sform1.id.focus();     8 Y% y7 d# g5 u- p( E( m1 r
   return false;     
& Y( L6 @5 [/ }8 h3 e+ ^   }     
( q1 A4 J# O; X6 M) u& H  } / J/ n* k" [! i9 r
  chineseid = document.sform1.chineseid.value;     ; J+ U6 e; d* I* ^" K# t: ]( `
if (chineseid == "")     
9 D* z3 ?, ]- j$ O% J' M  {     " Z. `- f" w3 u9 }4 F
  alert("请输入中文昵称");     
$ \$ L. z; [. ?" Y/ r4 f. x  document.sform1.chineseid.focus();     " S% r* Y/ {" c( ~6 k+ g
  return false;     
1 B: x. R- J2 q* v0 C+ W& d  }   
7 L6 v9 p" v, p: c5 z password = document.sform1.password.value;     ! r, o! s" e/ L  O* x
if (password == "")     & A( X5 T/ b/ S  W6 x7 F* l, R
  {     0 j' Z% E: M6 V
  alert("请输入登陆密码");     
' G5 P- v( ?* J' z: v! n0 o  document.sform1.password.focus();     5 R1 x4 w+ l% z' t+ ]% W
  return false;     ; U( o; V. [$ e" S7 a
  }
/ v: z5 C+ X  w6 t) \+ m2 ` password1 = document.sform1.password1.value;     
- R1 |* l" V' M; I$ l6 ? if (password>password1)     ! ?# d8 w" h: d2 v1 U$ ?
  {
% P8 B  _7 Y/ G- k* e     alert("重复密码与登陆密码不相同");     
9 {% @- B0 D/ A* }; c9 r  document.sform1.password.focus();
* B# C! d. w; y1 b- `                                document.sform1.password1.focus();     . ~/ j& T6 }! e+ y; a7 Z
  return false;9 \; h  s1 E) X! S/ _
  }  9 k4 L+ \: b6 p8 u" o
if (password<password1)     1 C! j4 [' ]: v; J( M9 R4 o  \
  {; w- b* `# _; x# x
     alert("重复密码与登陆密码不相同");     
) d/ ^) ~! A% S( a, U0 {  document.sform1.password.focus(); 5 A8 W; f& O" Z" V: V) m' [9 l6 O& l
                                document.sform1.password1.focus();     , L3 [$ }* S% U$ \4 O
  return false;
, x) t  X% {( [( t; H& U0 ~* I- C  }
2 U8 W9 P& q" K$ A; p6 O  s if (document.sform1.email.value == "")     
7 z1 b8 ]2 i+ \9 C8 h  {     - u7 M) O7 y/ C  x' m+ |
  alert("请输入您的E-MAIL地址");     9 f0 ?3 E" H1 v1 M
  document.sform1.email.focus();     7 q" I# X7 p) ?7 X* Q) ?: L8 V4 O
  return false;     
3 t2 C) q9 E/ m- K& n9 r1 N  }     
, d: ^. g# F. [4 |! {      + }# {+ S: Y: N+ @* w0 e
email=document.sform1.email.value;      ! r" m0 T4 J6 b' ]3 E1 S
emailerr=0     
1 d6 b9 m" R8 J' m* V for (i=0; i<email.length; i++)     4 ~5 W, H5 g& U8 \/ j3 b* O
  {     ; U/ G) P: t$ I2 H3 w3 \5 z4 t) |
  if ((email.charAt(i) == "@") & (email.length > 5))     
2 ?# g/ ]& }6 M6 \! m4 s, I. i  |   {     ; ]. c. s# \& ~8 ~8 d) H
     emailerr=emailerr+1     4 K! P" m1 C, N/ S7 K# S9 ]
   }     7 ~$ b. N9 b2 ?
  }     
9 a0 Z0 M8 {( F2 r3 | if (emailerr != 1)     
3 H! N; {+ v; W: O3 {' U  {     2 Z  Y7 C" g& r. Z+ ?2 ?, k! J
  alert("请输入正确的E-MAIL地址");     / J6 T& U# n. G( l% p
  document.sform1.email.focus();     9 l/ _. W' S/ `9 V; p
  return false;     
/ X! L7 G8 Q/ o, _2 f  }           
3 j; k: C1 C, V4 o2 n) r  5 w3 U, }7 E) Z
if (document.sform1.checkask.value=="")
6 K; [& A) T/ s0 t0 \! W  { 9 W2 j" o+ c! [8 C4 _
   alert("密码提示问题不能为空");     1 n7 I, N9 I" @4 y& M
   document.sform1.checkask.focus();     / Z  ?: m4 i& g3 o2 N
   return false;  / K( X" v' N7 R9 i5 N7 ?! z. s
  } % `0 X0 {1 c  a7 |0 Y0 r6 y
if (document.sform1.checkans.value=="")
* \- Y9 R$ `1 O- f4 \9 {( _  {
% t, {: G; P! f, K! I% p   alert("您的密码提示问题答案不能为空"); 8 O6 e' ]1 p  r* {  S+ U
   document.sform1.checkans.focus();     . c6 {5 [! u: v$ f% e' n+ Y3 ~
   return false;  
% f6 A: L/ B0 z3 i9 L  }
- b8 G4 P4 ~2 f7 F return true;     ) R$ R+ Q2 @! w; ^6 q0 {% U
     8 G3 z5 E2 l" m8 n
} 5 c( `7 L7 ~; T% b. O
</script>

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