返回列表 发帖

一个注册表单验证的js

这个脚本对你可能有帮助:! `: S; z/ I  Z3 ~+ ~. |
<script language="javascript">     ! c- P9 P! R9 @  z$ r7 p: e3 Q
function IsDigit(cCheck)     
) L/ ], h9 \, d; j6 g* C0 R& l% q {     9 K2 M5 N$ p4 d8 u  {+ U7 |' G
return (('0'<=cCheck) && (cCheck<='9'));     
6 V6 H( Z) r2 j$ M }     $ |3 ]# g! F4 {- U) K: \3 p
     
* k/ Z- L/ Q2 m2 Y9 c: Lfunction IsAlpha(cCheck)     ! \6 Q# [* {: n8 b9 V$ H8 V+ w
{     3 I& k3 |9 Y' C# \1 f
return ((('a'<=cCheck) && (cCheck<='z')) || (('A'<=cCheck) && (cCheck<='Z')))     * `: k7 r. {, }) {
}              2 D" L1 o6 K, }! Q  o: [3 f( a
      
, y/ C+ S1 B" L! x  N7 ~6 Z$ lfunction IsaNull(cCheck)          : \! R  ~& ]: s' V
{          : H/ m8 i! U$ S# r7 ~" I
return(cCheck != " ")         9 d$ C4 R2 T9 ~5 a5 h8 ]
}                              
" z3 M+ c0 R, U+ B$ |      
! O! S/ S& v0 R1 qfunction checkform()     
6 A; U& g' a) x  o" n9 f: V{ & l1 L- @. \6 w9 {% y# R6 G5 ^
  id = document.sform1.id.value;     ' Q. i) z% N; x0 A" y3 v! |2 i$ }
if (id == "")     " I0 o* l( d/ j3 v8 O) q, N
  {     $ k. Z6 [3 d% x
  alert("请输入注册名");     
8 o  x- H4 Q" W, h$ S7 F  document.sform1.id.focus();     
1 Z. ^$ Y; ], Z- J+ I; d  return false;     & G$ J4 K" F9 p9 v
  }     
: T5 [1 F6 k% W1 ^: D5 U. P, }: R       @( S# I) d2 d, v; r6 |4 e) \* W  \
for (nIndex=0; nIndex<id.length; nIndex++)     + L( G1 ^9 j( C, }- r
  {     
( i! x7 G# |6 M% N4 f0 k  cCheck = id.charAt(nIndex);     ! n" G' Y3 Z  x( ^' q6 I
  if (!(IsDigit(cCheck) || IsAlpha(cCheck) || cCheck=='-' || cCheck=='_' || cCheck=='.'))     / m+ B& k, @' c+ r; A
   {     9 \6 Y( U% C  W3 T# U
   alert("用户名只能使用字母、数字以及-、_和.,并且不能使用中文");     + ~; v! M' s. O0 a  I1 s# w
   document.sform1.id.focus();     
" X8 _. J2 ]9 w+ x$ F+ a   return false;     
+ i  C" {) R3 z0 _   }     6 V/ {0 _1 b* w$ G8 w
  } ! s7 [9 W  {* Q+ e. N
  chineseid = document.sform1.chineseid.value;     
/ g6 h0 \. E! |* W if (chineseid == "")     
2 ]1 z2 @& \6 {, L  g. ?% f  {     
4 B% q& w5 y( E* e0 `: ^/ M: E  alert("请输入中文昵称");     
$ r. R5 R& P- W  document.sform1.chineseid.focus();     
: W' S+ f( `$ b4 A7 w0 L& E  return false;     4 v6 r; F0 f0 f" f' G9 F
  }   
5 r3 t0 H* o$ K# n5 v( }: V' I password = document.sform1.password.value;     
8 ~+ x$ z  {* z* X5 R8 k6 M* M if (password == "")     ( a. n8 z+ I  `4 X6 F; Y4 O* S
  {     3 {: l7 D, K/ Z& h% {# O
  alert("请输入登陆密码");     % n5 i6 V$ ?4 R" m0 j! V
  document.sform1.password.focus();     0 @. m& S8 g" f7 e5 w5 m) z. j2 U: e
  return false;     ; C: L' G7 C. M3 i. L) k  A! k
  }
8 J2 L  W; R8 Q( V2 _4 E4 ^, m password1 = document.sform1.password1.value;     
4 ~8 B. O7 |0 j" d" l if (password>password1)     
  @( z" u! \8 T$ O" I  {
6 I& w# A& U" Q3 I6 Q     alert("重复密码与登陆密码不相同");     ; D" s( ?9 g5 G/ u# s* z# o& E
  document.sform1.password.focus(); ! m8 F8 Z/ c2 Z
                                document.sform1.password1.focus();     
7 U% d0 H5 `: |) B1 C7 w1 l' _  return false;
& j3 l) o: u2 F# M$ {  }  8 E* C3 z2 @/ f0 C9 v
if (password<password1)     
& L' ]/ S4 Q& J" x- z  {
1 r' O5 K+ O7 s  Q. s( h     alert("重复密码与登陆密码不相同");     
8 K/ L1 n- J! T" W5 k8 Z! A9 `, v9 Q  document.sform1.password.focus(); : C8 e, l3 g$ S. r
                                document.sform1.password1.focus();     
: t! s  V0 T7 b4 @/ l% Y  return false;% g7 T# l4 c5 Y
  }
0 Y" P8 B# s' n6 _9 U/ ] if (document.sform1.email.value == "")     ( i% s7 o8 y8 u( K* v$ l
  {     3 f7 V0 ]0 C5 `& |' k
  alert("请输入您的E-MAIL地址");     
- P. n8 o; I, j# P8 H! i# \; C  document.sform1.email.focus();     5 F' I) O3 I0 r. N) }; d
  return false;     
9 G9 ?+ y8 \3 d- \  }     
, Z5 Q2 W! d- A" H. F. X2 o      
! k/ a/ S1 v) Y. g4 H email=document.sform1.email.value;      
& u! n' O, X6 \. n0 l emailerr=0     
, z4 ]. R0 _- [% Y8 E* q- Y for (i=0; i<email.length; i++)     
; u: u4 x$ u8 J0 N! t  {     
' F, h2 S. j' V  if ((email.charAt(i) == "@") & (email.length > 5))     # b5 \* W3 N9 q
   {     
; J2 W7 b5 l* X- A- a     emailerr=emailerr+1     : B7 e4 r. B5 [" i
   }     
+ U  @% Y7 V) V( P2 X' ]2 {. U  e# H  }     $ q+ s0 o7 Z- V% A4 {( F0 T
if (emailerr != 1)     
/ `6 i. Z% X7 U) F  {     7 K0 H) p( W6 D: Q: P
  alert("请输入正确的E-MAIL地址");     
' D$ \/ G6 d8 c0 T  document.sform1.email.focus();     
( x: H# h3 Q$ z3 i- R: E  return false;     
# o0 D/ K: w1 t" \' x6 |  }           
# |% d9 l3 T" ?$ D" I9 H7 Y7 S; u2 ^  , t0 x: |5 m% P, ~6 e+ b3 @
if (document.sform1.checkask.value=="")
1 x2 r. [& m- D% |9 P  { / `5 _0 q( Y; }8 _' F- h
   alert("密码提示问题不能为空");     
; y( k* n+ S" P   document.sform1.checkask.focus();     7 T& T& A3 Q. K8 @/ F) x* B
   return false;  : V7 {1 j  P' N! q$ c9 D
  } 8 J, O5 t4 {9 u0 n# I( K
if (document.sform1.checkans.value=="") " O" \  y. D8 r. c5 L$ s1 k
  { ; n' b2 V6 U4 i( g) N: ^# v! s
   alert("您的密码提示问题答案不能为空");
, J8 U' j- a: |: X( W% E   document.sform1.checkans.focus();     ; @3 R  T  V& z" ]% K& n# _- l
   return false;  % Z/ b! a% I% f3 [
  }# f6 r3 G9 d. c% b* B2 A, g. I
return true;     ; m3 ?( s. _$ [8 B/ S: J1 M1 R3 W
     # @5 a# e/ I( ]
}
2 C) d) E, i+ w0 P* Z1 m</script>

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