返回列表 发帖

一个注册表单验证的js

这个脚本对你可能有帮助:
& z* v( s6 h+ \. n<script language="javascript">     " B) G0 p5 V. l5 M
function IsDigit(cCheck)     
* r* `$ z0 Y) j. W' S: D {     
# ^* o1 ~9 G; o6 t return (('0'<=cCheck) && (cCheck<='9'));     
+ P; J6 L. c& |( Z- U& [* t }     - J/ I- T7 j. a1 U* d) v$ X  m  z
     ) X# T! G' Z, @+ \! E! S% l4 M
function IsAlpha(cCheck)     1 f' u4 H8 ^3 d4 q' f
{     
- m0 \# j: y$ y return ((('a'<=cCheck) && (cCheck<='z')) || (('A'<=cCheck) && (cCheck<='Z')))     
% C$ S4 o' u! {1 h2 B3 i }              5 S' w1 S' l/ ~8 t
      
+ m/ r) n8 A7 _9 afunction IsaNull(cCheck)          7 R; n$ Y) k3 L0 V! i
{          $ S5 L, [- G% [& T% d- I
return(cCheck != " ")         
" j2 j9 s! e- d/ P }                              
) o% D6 P0 F9 X0 z7 b, I      
  X) ]9 v+ I6 @! lfunction checkform()     
8 u, }* l8 V( W: c4 e# F5 E{ 6 d4 \/ q2 t6 [6 q# k4 E
  id = document.sform1.id.value;     
6 `1 M  y  K2 x if (id == "")     
' }% K: B5 a# [  ^3 y  {     + v0 |" y4 Y- O3 K
  alert("请输入注册名");     
  Q2 t9 M( s5 m" a  document.sform1.id.focus();     / Z+ k) {5 N3 w$ ]3 [, N
  return false;     
3 O6 d$ k. K4 i$ a9 X+ F  }     5 o; j; V  I5 f3 k! |. n! g: |- D/ g; Y
     . n; P3 C* `' l
for (nIndex=0; nIndex<id.length; nIndex++)     
7 ^% P6 |' S% f9 g  {     
& m* i$ ~2 b, {' w# a  cCheck = id.charAt(nIndex);     
" _# O* F. Z1 s  if (!(IsDigit(cCheck) || IsAlpha(cCheck) || cCheck=='-' || cCheck=='_' || cCheck=='.'))     
: `+ i( _( Y3 n. D- B% l   {     
! q2 z+ j. O0 E4 Y# k   alert("用户名只能使用字母、数字以及-、_和.,并且不能使用中文");     . d* w' H* a9 k1 u
   document.sform1.id.focus();     ' U' G2 `- A7 G& ^: t2 `0 ^
   return false;     - [2 C5 o8 W! r, ^) _
   }     8 V! M6 h3 P0 o% ?2 V5 V, L
  }
" D! z, X1 q1 h4 |0 r- a  chineseid = document.sform1.chineseid.value;     9 h. x0 O/ D' n  w
if (chineseid == "")     
) }/ N! W, j( M( o6 |: F: r/ B  {     
0 M9 T; e  ^: a  alert("请输入中文昵称");     
: b0 }- w7 N8 b) Q% e4 Y  n+ F9 @  document.sform1.chineseid.focus();     
) z# B, u3 E$ Y  return false;     
/ N. L( ?0 `9 E! E0 J* t6 B  }    5 B+ v9 `' U7 U( s
password = document.sform1.password.value;     
, q5 T, h; H2 F5 o; l% l, S if (password == "")     2 P2 E" R- ]. S0 |3 [9 r
  {     + m7 s9 p( S$ y- [
  alert("请输入登陆密码");     1 C. D$ I3 c( D; w: M% q2 ?9 w
  document.sform1.password.focus();     2 f, \& o' }( Y7 P) L, M
  return false;     2 |# Y# h! y) W
  } & ]# L. R" r9 `: E- ^' F3 `
password1 = document.sform1.password1.value;     
# T; T1 b2 b5 h: U' z4 { if (password>password1)     1 P6 n" q* E& l; D+ J
  {9 l  T( z" L/ U0 E$ P
     alert("重复密码与登陆密码不相同");     
& y$ n( w7 Y/ ]* u2 k  document.sform1.password.focus();
; z- Z% }5 {# H                                document.sform1.password1.focus();     
' L9 k8 T" o- V/ ]. y/ l" i  return false;
* w. c2 g1 p9 z" D7 w  }  
' w3 U6 E9 U# q& K8 \7 }( Y/ vif (password<password1)     
9 j+ ~: M* M$ r  {: P( R& J5 X" }" U% r0 S
     alert("重复密码与登陆密码不相同");     
5 N4 g# I6 ^! H0 V4 K7 T" \& c  document.sform1.password.focus();
0 W% [. X0 T/ G0 E$ e                                document.sform1.password1.focus();     
3 Z, x  ~( y) Q/ O3 G  return false;
) }8 f" l5 O' S9 X) U1 r) K) Z% p0 r  }
9 b- u2 Y  g  G& g# a/ k if (document.sform1.email.value == "")     
" Z1 b' q% e# E* E5 B4 K  {     
! d8 v6 ~7 {2 o9 i( p  alert("请输入您的E-MAIL地址");     , U5 v2 {4 q" [1 v: o0 C5 ~) S
  document.sform1.email.focus();     
6 {% l) E7 p7 G; [; ]& X7 g  return false;     ! L' I- x$ J8 E
  }     
. j: e7 d) s7 p' E6 M      ! ^: z5 |: \. s* D; j# ^  Q* L# q3 ~
email=document.sform1.email.value;      $ ~, @+ W& u7 C2 ^. z/ I- U2 ^3 R# {
emailerr=0     
; l9 z, e2 ^& E8 W5 ^$ H. @5 X8 s for (i=0; i<email.length; i++)     
! v% }: ?9 G9 i: C  {     % k) E6 z1 m2 m' H7 o- d, A7 O( Y
  if ((email.charAt(i) == "@") & (email.length > 5))     
4 u1 x, b5 b" B) U: [# t4 X   {     , d3 g1 E' H) N( h# v& {+ \/ B
     emailerr=emailerr+1     8 I2 |* A" E" h; w, h# C
   }     # d4 W; u+ g0 X' B6 i3 |6 a+ H
  }     
* X$ C1 {1 x8 f* ^3 V  U/ { if (emailerr != 1)     ( L  @  U* @8 {$ P- w
  {     
7 [' |4 P: z1 O6 B* n0 @  alert("请输入正确的E-MAIL地址");     
& v( E- H" D9 n$ d/ `  document.sform1.email.focus();     3 v# k' R9 ?4 S# L% D% w! j
  return false;     9 @; p) G$ I$ h
  }           - D) Q, N  Y, I7 `, }
  , W. ~3 x1 i; _; {2 |6 Z) @5 C# s
if (document.sform1.checkask.value=="")
+ [  B  [4 }6 C+ V( D9 E/ \4 `  {
  J/ x1 Z4 V2 }* g3 ?   alert("密码提示问题不能为空");     
3 @$ Q/ b. w3 m; q7 t7 m. ]   document.sform1.checkask.focus();       i! G8 M! E/ V. |8 n; @7 B# j
   return false;  6 s+ Z' I2 h* j# d- v* O
  } 9 R) y6 E3 f9 v* V% M" j" K7 u
if (document.sform1.checkans.value=="")
0 m- @( [  P) G3 C4 M5 Y7 c  {   ]7 X8 c% A5 [) E2 I5 L9 Z8 U
   alert("您的密码提示问题答案不能为空");
, F! v; ~- |7 z! u   document.sform1.checkans.focus();     
1 p  K! q2 U4 w3 v   return false;  
6 U. @  q6 b4 V9 U9 \/ _+ Z( m  }
2 ?) v* |, O! ?+ E! a return true;     
" e# j* }& S1 D3 R1 K     $ g9 k5 _. T! Y4 I' z
}   c! x4 Y3 F* m( k+ y! k1 t
</script>

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