📄 用javascript判断日期、数字、整数和特殊字符 - 东猫北熊的技术积累 - 博客园.mht
字号:
style=3D"COLOR: #000000"> </SPAN><SPAN=20
style=3D"COLOR: #0000ff">true</SPAN><SPAN=20
style=3D"COLOR: #000000">;<BR>}<BR></SPAN><SPAN=20
style=3D"COLOR: #0000ff">else</SPAN><SPAN=20
style=3D"COLOR: #000000"><BR>{<BR></SPAN><SPAN=20
style=3D"COLOR: #0000ff">return</SPAN><SPAN=20
style=3D"COLOR: #000000"> </SPAN><SPAN=20
style=3D"COLOR: #0000ff">false</SPAN><SPAN=20
style=3D"COLOR: #000000">;<BR>}<BR>}<BR><BR></SPAN><SPAN=20
style=3D"COLOR: #008000">/*</SPAN><SPAN=20
style=3D"COLOR: =
#008000">*<BR>IsNumber: =E7=94=A8=E4=BA=8E=E5=88=A4=E6=96=AD=E4=B8=80=
=E4=B8=AA=E6=95=B0=E5=AD=97=E5=9E=8B=E5=AD=97=E7=AC=A6=E4=B8=B2=E6=98=AF=E5=
=90=A6=E4=B8=BA=E6=95=B0=E5=80=BC=E5=9E=8B=EF=BC=8C<BR>=E8=BF=98=E5=8F=AF=
=E5=88=A4=E6=96=AD=E6=98=AF=E5=90=A6=E6=98=AF=E6=AD=A3=E6=95=B0=E6=88=96=E8=
=B4=9F=E6=95=B0=EF=BC=8C=E8=BF=94=E5=9B=9E=E5=80=BC=E4=B8=BAtrue=E6=88=96=
false<BR>string: =E9=9C=80=E8=A6=81=E5=88=A4=E6=96=AD=E7=9A=84=E5=AD=
=97=E7=AC=A6=E4=B8=B2<BR>sign: =E8=8B=A5=E8=A6=81=E5=88=A4=E6=96=AD=E6=
=98=AF=E6=AD=A3=E8=B4=9F=E6=95=B0=E6=98=AF=E4=BD=BF=E7=94=A8=EF=BC=8C=E6=98=
=AF=E6=AD=A3=E7=94=A8=E2=80=B2+=E2=80=B2=EF=BC=8C=E8=B4=9F=E2=80=B2-=E2=80=
=B2=EF=BC=8C=E4=B8=8D=E7=94=A8=E5=88=99=E8=A1=A8=E7=A4=BA=E4=B8=8D=E4=BD=9C=
=E5=88=A4=E6=96=AD<BR>Author: PPDJ<BR>sample:<BR>var a =3D=
=E2=80=B2123=E2=80=B2;<BR>if (IsNumber(a))<BR>{<BR>alert(=E2=80=
=B2a is a number=E2=80=B2);<BR>}<BR>if (IsNumber(a,=E2=
=80=B2+=E2=80=B2))<BR>{<BR>alert(a is a positive numb=
er);<BR>}<BR>if (IsNumber(a,=E2=80=B2-=E2=80=B2))<BR>{<BR>alert(=E2=80=
=B2a is a negative number=E2=80=B2);<BR>}<BR></SPAN><=
SPAN=20
style=3D"COLOR: #008000">*/</SPAN><SPAN=20
style=3D"COLOR: =
#000000"><BR><BR>function IsNumber(</SPAN><SPAN=20
style=3D"COLOR: #0000ff">string</SPAN><SPAN=20
style=3D"COLOR: =
#000000">,sign)<BR>{<BR>var number;<BR></SPAN><SPAN=20
style=3D"COLOR: #0000ff">if</SPAN><SPAN=20
style=3D"COLOR: #000000"> (</SPAN><SPAN=20
style=3D"COLOR: #0000ff">string</SPAN><SPAN=20
style=3D"COLOR: #000000">=3D=3D</SPAN><SPAN=20
style=3D"COLOR: #0000ff">null</SPAN><SPAN=20
style=3D"COLOR: #000000">) </SPAN><SPAN=20
style=3D"COLOR: #0000ff">return</SPAN><SPAN=20
style=3D"COLOR: #000000"> </SPAN><SPAN=20
style=3D"COLOR: #0000ff">false</SPAN><SPAN=20
style=3D"COLOR: #000000">;<BR></SPAN><SPAN=20
style=3D"COLOR: #0000ff">if</SPAN><SPAN=20
style=3D"COLOR: #000000"> ((sign</SPAN><SPAN=20
style=3D"COLOR: #000000">!=3D</SPAN><SPAN=20
style=3D"COLOR: #0000ff">null</SPAN><SPAN=20
style=3D"COLOR: #000000">) </SPAN><SPAN=20
style=3D"COLOR: #000000">&&</SPAN><SPAN=20
style=3D"COLOR: #000000"> (sign</SPAN><SPAN=20
style=3D"COLOR: #000000">!=3D</SPAN><SPAN style=3D"COLOR: =
#000000">=E2=80=B2</SPAN><SPAN=20
style=3D"COLOR: #000000">-</SPAN><SPAN=20
style=3D"COLOR: #000000">=E2=80=B2) </SPAN><SPAN=20
style=3D"COLOR: #000000">&&</SPAN><SPAN=20
style=3D"COLOR: #000000"> (sign</SPAN><SPAN=20
style=3D"COLOR: #000000">!=3D</SPAN><SPAN style=3D"COLOR: =
#000000">=E2=80=B2</SPAN><SPAN=20
style=3D"COLOR: #000000">+</SPAN><SPAN=20
style=3D"COLOR: =
#000000">=E2=80=B2))<BR>{<BR>alert(=E2=80=B2IsNumber(</SPAN><SPAN=20
style=3D"COLOR: #0000ff">string</SPAN><SPAN=20
style=3D"COLOR: =
#000000">,sign)=E7=9A=84=E5=8F=82=E6=95=B0=E5=87=BA=E9=94=99=EF=BC=9A&nbs=
p;sign=E4=B8=BAnull=E6=88=96</SPAN><SPAN=20
style=3D"COLOR: #000000">"</SPAN><SPAN style=3D"COLOR: =
#000000">-</SPAN><SPAN=20
style=3D"COLOR: #000000">"</SPAN><SPAN style=3D"COLOR: =
#000000">=E6=88=96</SPAN><SPAN=20
style=3D"COLOR: #000000">"</SPAN><SPAN style=3D"COLOR: =
#000000">+</SPAN><SPAN=20
style=3D"COLOR: #000000">"</SPAN><SPAN=20
style=3D"COLOR: #000000">=E2=80=B2);<BR></SPAN><SPAN=20
style=3D"COLOR: #0000ff">return</SPAN><SPAN=20
style=3D"COLOR: #000000"> </SPAN><SPAN=20
style=3D"COLOR: #0000ff">false</SPAN><SPAN=20
style=3D"COLOR: #000000">;<BR>}<BR>number </SPAN><SPAN=20
style=3D"COLOR: #000000">=3D</SPAN><SPAN=20
style=3D"COLOR: #000000"> </SPAN><SPAN=20
style=3D"COLOR: #0000ff">new</SPAN><SPAN=20
style=3D"COLOR: #000000"> Number(</SPAN><SPAN=20
style=3D"COLOR: #0000ff">string</SPAN><SPAN=20
style=3D"COLOR: #000000">);<BR></SPAN><SPAN=20
style=3D"COLOR: #0000ff">if</SPAN><SPAN=20
style=3D"COLOR: =
#000000"> (isNaN(number))<BR>{<BR></SPAN><SPAN=20
style=3D"COLOR: #0000ff">return</SPAN><SPAN=20
style=3D"COLOR: #000000"> </SPAN><SPAN=20
style=3D"COLOR: #0000ff">false</SPAN><SPAN=20
style=3D"COLOR: #000000">;<BR>}<BR></SPAN><SPAN=20
style=3D"COLOR: #0000ff">else</SPAN><SPAN=20
style=3D"COLOR: #000000"> </SPAN><SPAN=20
style=3D"COLOR: #0000ff">if</SPAN><SPAN=20
style=3D"COLOR: #000000"> ((sign</SPAN><SPAN=20
style=3D"COLOR: #000000">=3D=3D</SPAN><SPAN=20
style=3D"COLOR: #0000ff">null</SPAN><SPAN=20
style=3D"COLOR: #000000">) </SPAN><SPAN=20
style=3D"COLOR: #000000">||</SPAN><SPAN=20
style=3D"COLOR: #000000"> (sign</SPAN><SPAN=20
style=3D"COLOR: #000000">=3D=3D</SPAN><SPAN style=3D"COLOR: =
#000000">=E2=80=B2</SPAN><SPAN=20
style=3D"COLOR: #000000">-</SPAN><SPAN=20
style=3D"COLOR: #000000">=E2=80=B2 </SPAN><SPAN=20
style=3D"COLOR: #000000">&&</SPAN><SPAN=20
style=3D"COLOR: #000000"> number</SPAN><SPAN=20
style=3D"COLOR: #000000"><</SPAN><SPAN=20
style=3D"COLOR: #000000">0</SPAN><SPAN=20
style=3D"COLOR: #000000">) </SPAN><SPAN=20
style=3D"COLOR: #000000">||</SPAN><SPAN=20
style=3D"COLOR: #000000"> (sign</SPAN><SPAN=20
style=3D"COLOR: #000000">=3D=3D</SPAN><SPAN style=3D"COLOR: =
#000000">=E2=80=B2</SPAN><SPAN=20
style=3D"COLOR: #000000">+</SPAN><SPAN=20
style=3D"COLOR: #000000">=E2=80=B2 </SPAN><SPAN=20
style=3D"COLOR: #000000">&&</SPAN><SPAN=20
style=3D"COLOR: #000000"> number</SPAN><SPAN=20
style=3D"COLOR: #000000">></SPAN><SPAN=20
style=3D"COLOR: #000000">0</SPAN><SPAN=20
style=3D"COLOR: #000000">))<BR>{<BR></SPAN><SPAN=20
style=3D"COLOR: #0000ff">return</SPAN><SPAN=20
style=3D"COLOR: #000000"> </SPAN><SPAN=20
style=3D"COLOR: #0000ff">true</SPAN><SPAN=20
style=3D"COLOR: #000000">;<BR>}<BR></SPAN><SPAN=20
style=3D"COLOR: #0000ff">else</SPAN><SPAN=20
style=3D"COLOR: #000000"><BR></SPAN><SPAN=20
style=3D"COLOR: #0000ff">return</SPAN><SPAN=20
style=3D"COLOR: #000000"> </SPAN><SPAN=20
style=3D"COLOR: #0000ff">false</SPAN><SPAN=20
style=3D"COLOR: #000000">;<BR>}<BR><BR><BR></SPAN><SPAN=20
style=3D"COLOR: #008000">/*</SPAN><SPAN=20
style=3D"COLOR: =
#008000">*<BR>SpecialString: =E7=94=A8=E4=BA=8E=E5=88=A4=E6=96=AD=E4=
=B8=80=E4=B8=AA=E5=AD=97=E7=AC=A6=E4=B8=B2=E6=98=AF=E5=90=A6=E5=90=AB=E6=9C=
=89=E6=88=96=E4=B8=8D=E5=90=AB=E6=9C=89=E6=9F=90=E4=BA=9B=E5=AD=97=E7=AC=A6=
<BR><BR>=E8=BF=94=E5=9B=9E=E5=80=BC=EF=BC=9A<BR>true=E6=88=96false<BR><BR=
>=E5=8F=82=E6=95=B0=EF=BC=9A<BR>string =EF=BC=9A =E9=9C=80=E8=A6=
=81=E5=88=A4=E6=96=AD=E7=9A=84=E5=AD=97=E7=AC=A6=E4=B8=B2<BR>compare =
;=EF=BC=9A =E6=AF=94=E8=BE=83=E7=9A=84=E5=AD=97=E7=AC=A6=E4=B8=B2(=E5=
=9F=BA=E5=87=86=E5=AD=97=E7=AC=A6=E4=B8=B2)<BR>BelongOrNot=EF=BC=9A =
true=E6=88=96false=EF=BC=8C=E2=80=9Ctrue=E2=80=9D=E8=A1=A8=E7=A4=BAstring=
=E7=9A=84=E6=AF=8F=E4=B8=80=E4=B8=AA=E5=AD=97=E7=AC=A6=E9=83=BD=E5=8C=85=E5=
=90=AB=E5=9C=A8compare=E4=B8=AD=EF=BC=8C<BR>=E2=80=9Cfalse=E2=80=9D=E8=A1=
=A8=E7=A4=BAstring=E7=9A=84=E6=AF=8F=E4=B8=80=E4=B8=AA=E5=AD=97=E7=AC=A6=E9=
=83=BD=E4=B8=8D=E5=8C=85=E5=90=AB=E5=9C=A8compare=E4=B8=AD<BR><BR>Author:=
PPDJ<BR>sample1:<BR>var str =3D =E2=80=B2123G=E2=80=B2=
;<BR>if (SpecialString(str,=E2=80=B21234567890=E2=80=B2))<BR>{<BR>al=
ert(=E2=80=B2Yes, All the letter of the str=
ing in =E2=80=B21234567890=E2=80=B2=E2=80=B2);<BR>}<BR>else<BR>=
{<BR>alert(=E2=80=B2No, one or more letters of&n=
bsp;the string not in =E2=80=B21234567890=E2=80=B2=E2=
=80=B2);<BR>}<BR>=E7=BB=93=E6=9E=9C=E6=89=A7=E8=A1=8C=E7=9A=84=E6=98=AFel=
se=E9=83=A8=E5=88=86<BR>sample2:<BR>var password =3D =E2=80=
=B21234=E2=80=B2;<BR>if (!SpecialString(password,=E2=80=B2=E2=80=B2"=
@#$%=E2=80=B2,false)) <BR>{<BR>alert(=E2=80=B2Yes, The pas=
sword is correct.=E2=80=B2);<BR>}<BR>else<BR>{<BR>alert(=E2=80=B2=
No, The password is contain one or mor=
e letters of =E2=80=B2"@#$%=E2=80=B2=E2=80=B2);<BR>} =
<BR>=E7=BB=93=E6=9E=9C=E6=89=A7=E8=A1=8C=E7=9A=84=E6=98=AFelse=E9=83=A8=E5=
=88=86<BR></SPAN><SPAN style=3D"COLOR: #008000">*/</SPAN><SPAN=20
style=3D"COLOR: =
#000000"><BR>function SpecialString(</SPAN><SPAN=20
style=3D"COLOR: #0000ff">string</SPAN><SPAN=20
style=3D"COLOR: =
#000000">,compare,BelongOrNot)<BR>{<BR></SPAN><SPAN=20
style=3D"COLOR: #0000ff">if</SPAN><SPAN=20
style=3D"COLOR: #000000"> ((</SPAN><SPAN=20
style=3D"COLOR: #0000ff">string</SPAN><SPAN=20
style=3D"COLOR: #000000">=3D=3D</SPAN><SPAN=20
style=3D"COLOR: #0000ff">null</SPAN><SPAN=20
style=3D"COLOR: #000000">) </SPAN><SPAN=20
style=3D"COLOR: #000000">||</SPAN><SPAN=20
style=3D"COLOR: #000000"> (compare</SPAN><SPAN=20
style=3D"COLOR: #000000">=3D=3D</SPAN><SPAN=20
style=3D"COLOR: #0000ff">null</SPAN><SPAN=20
style=3D"COLOR: #000000">) </SPAN><SPAN=20
style=3D"COLOR: #000000">||</SPAN><SPAN=20
style=3D"COLOR: #000000"> ((BelongOrNot</SPAN><SPAN=20
style=3D"COLOR: #000000">!=3D</SPAN><SPAN=20
style=3D"COLOR: #0000ff">null</SPAN><SPAN=20
style=3D"COLOR: #000000">) </SPAN><SPAN=20
style=3D"COLOR: #000000">&&</SPAN><SPAN=20
style=3D"COLOR: #000000"> (BelongOrNot</SPAN><SPAN=20
style=3D"COLOR: #000000">!=3D</SPAN><SPAN=20
style=3D"COLOR: #0000ff">true</SPAN><SPAN=20
style=3D"COLOR: #000000">) </SPAN><SPAN=20
style=3D"COLOR: #000000">&&</SPAN><SPAN=20
style=3D"COLOR: #000000"> (BelongOrNot</SPAN><SPAN=20
style=3D"COLOR: #000000">!=3D</SPAN><SPAN=20
style=3D"COLOR: #0000ff">false</SPAN><SPAN=20
style=3D"COLOR: =
#000000">)))<BR>{<BR>alert(=E2=80=B2function SpecialString(</SPAN><S=
PAN=20
style=3D"COLOR: #0000ff">string</SPAN><SPAN=20
style=3D"COLOR: =
#000000">,compare,BelongOrNot)=E5=8F=82=E6=95=B0=E9=94=99=E8=AF=AF=E2=80=B2=
);<BR></SPAN><SPAN=20
style=3D"COLOR: #0000ff">return</SPAN><SPAN=20
style=3D"COLOR: #000000"> </SPAN><SPAN=20
style=3D"COLOR: #0000ff">false</SPAN><SPAN=20
style=3D"COLOR: #000000">;<BR>}<BR></SPAN><SPAN=20
style=3D"COLOR: #0000ff">if</SPAN><SPAN=20
style=3D"COLOR: #000000"> (BelongOrNot</SPAN><SPAN=20
style=3D"COLOR: #000000">=3D=3D</SPAN><SPAN=20
style=3D"COLOR: #0000ff">null</SPAN><SPAN=20
style=3D"COLOR: #000000"> </SPAN><SPAN=20
style=3D"COLOR: #000000">||</SPAN><SPAN=20
style=3D"COLOR: #000000"> BelongOrNot</SPAN><SPAN=20
style=3D"COLOR: #000000">=3D=3D</SPAN><SPAN=20
style=3D"COLOR: #0000ff">true</SPAN><SPAN=20
style=3D"COLOR: #000000">)<BR>{<BR></SPAN><SPAN=20
style=3D"COLOR: #0000ff">for</SPAN><SPAN=20
style=3D"COLOR: #000000"> (var i</SPAN><SPAN=20
style=3D"COLOR: #000000">=3D</SPAN><SPAN style=3D"COLOR: =
#000000">0</SPAN><SPAN=20
style=3D"COLOR: #000000">;i{<BR></SPAN><SPAN=20
style=3D"COLOR: #0000ff">if</SPAN><SPAN=20
style=3D"COLOR: #000000"> (compare.indexOf(</SPAN><SPAN=20
style=3D"COLOR: #0000ff">string</SPAN><SPAN=20
style=3D"COLOR: #000000">.charAt(i))</SPAN><SPAN=20
style=3D"COLOR: #000000">=3D=3D-</SPAN><SPAN=20
style=3D"COLOR: #000000">1</SPAN><SPAN=20
style=3D"COLOR: #000000">)<BR></SPAN><SPAN=20
style=3D"COLOR: #0000ff">return</SPAN><SPAN=20
style=3D"COLOR: #000000"> </SPAN><SPAN=20
style=3D"COLOR: #0000ff">false</SPAN><SPAN=20
style=3D"COLOR: #000000"><BR>}<BR></SPAN><SPAN=20
style=3D"COLOR: #0000ff">return</SPAN><SPAN=20
style=3D"COLOR: #000000"> </SPAN><SPAN=20
style=3D"COLOR: #0000ff">true</SPAN><SPAN=20
style=3D"COLOR: #000000">;<BR>}<BR></SPAN><SPAN=20
style=3D"COLOR: #0000ff">else</SPAN><SPAN=20
style=3D"COLOR: #000000"><BR>{<BR></SPAN><SPAN=20
style=3D"COLOR: #0000ff">for</SPAN><SPAN=20
style=3D"COLOR: #000000"> (var i</SPAN><SPAN=20
style=3D"COLOR: #000000">=3D</SPAN><SPAN style=3D"COLOR: =
#000000">0</SPAN><SPAN=20
style=3D"COLOR: #000000">;i{<BR></SPAN><SPAN=20
style=3D"COLOR: #0000ff">if</SPAN><SPAN=20
style=3D"COLOR: #000000"> (compare.indexOf(</SPAN><SPAN=20
style=3D"COLOR: #0000ff">string</SPAN><SPAN=20
style=3D"COLOR: #000000">.charAt(i))</SPAN><SPAN=20
style=3D"COLOR: #000000">!=3D-</SPAN><SPAN=20
style=3D"COLOR: #000000">1</SPAN><SPAN=20
style=3D"COLOR: #000000">)<BR></SPAN><SPAN=20
style=3D"COLOR: #0000ff">return</SPAN><SPAN=20
style=3D"COLOR: #000000"> </SPAN><SPAN=20
style=3D"COLOR: #0000ff">false</SPAN><SPAN=20
style=3D"COLOR: #000000"><BR>}<BR></SPAN><SPAN=20
style=3D"COLOR: #0000ff">return</SPAN><SPAN=20
style=3D"COLOR: #000000"> </SPAN><SPAN=20
style=3D"COLOR: #0000ff">true</SPAN><SPAN=20
style=3D"COLOR: #000000">;<BR>}<BR>}<BR><BR><BR></SPAN><SPAN=20
style=3D"COLOR: #008000">//</SPAN><SPAN=20
style=3D"COLOR: #008000">--></SPAN><SPAN=20
style=3D"COLOR: #008000"><BR></SPAN><SPAN=20
style=3D"COLOR: #000000"><</SPAN><SPAN=20
style=3D"COLOR: #000000"> </SPAN><SPAN=20
style=3D"COLOR: #000000">/</SPAN><SPAN=20
style=3D"COLOR: #000000">script</SPAN><SPAN=20
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -