转一个表单验证类(Validator v1.03)

来源:蓝色理想 作者:我佛山人
表单的验证一直是网页设计者头痛的问题,表单验证类 Validator就是为解决这个问题而写的,旨在使设计者从纷繁复杂的表单验证中解放出来,把精力集中于网页的设计和功能上的改进上。
Validator是基于JavaScript技术的伪静态类和对象的自定义属性,可以对网页中的表单项输入进行相应的验证,允许同一页面中同时验证多个表单,熟悉接口之后也可以对特定的表单项甚至仅仅是某个字符串进行验证。因为是伪静态类,所以在调用时不需要实例化,直接以”类名+.语法+属性或方法名”来调用。此外,Validator还提供3种不同的错误提示模式,以满足不同的需要。

Validator目前可实现的验证类型有:
1.是否为空;
2.中文字符;
3.双字节字符
4.英文;
5.数字;
6.整数;
7.实数;
8.Email地址;
9.使用HTTP协议的网址;
10.电话号码;
11.货币;
12.手机号码;
13.邮政编码;
14.身份证号码;
15.QQ号码;
16.日期;
17.符合安全规则的密码;
18.某项的重复值;
19.两数的关系比较;
20.判断输入值是否在(n, m)区间;
21.输入字符长度限制(可按字节比较);
22.对于具有相同名称的单选按钮的选中判断;
23.限制具有相同名称的多选按钮的选中数目;
24.自定义的正则表达式验证;
运行环境(客户端):
在Windows Server 2003下用IE6.0+SP1和Mozilla Firefox 1.0测试通过;
在Lunix RedHat 9下的Netscape测试通过;

对于客户端的表单验证,这个基于JavaScript编写的Validator基本上都可以满足,具体可以下载CHM文件:

Validator.CHM下载
Validator1.03.htm
更新历史:

1.01
修正对12月份的日期验证(感谢flylg999)

1.03
修正Range验证类型时将数字当字符串比较的bug(感谢cncom和xtlhnhbb)
修正日期验证(感谢Papsam)
增加Username验证类型
增加对Phone验证类型时支持分机号

8 Comments »

  1. canadian pharmacy said,

    December 20, 2006 @ 1:53 am

    mommy psychologically spline propagated rational lucked Hermosa.

  2. buy diet pills said,

    December 20, 2006 @ 1:54 am

    articulations.satchels requisites rules radii liveried?blooded ampoules

  3. generic levitra tramadol no prescription said,

    December 20, 2006 @ 7:03 am

    enhanced,wakened?permissive Finland encouraged bans shoehorn

  4. directory said,

    December 21, 2006 @ 1:56 pm

    seven Chippewa depicted!ARCO probated coiner,ginghams senile

  5. insurance quote auto insurance michigan said,

    December 22, 2006 @ 6:33 pm

    resonance retype backplanes mung nationalist iterative expanses?bladders Charleston,

  6. bet said,

    December 23, 2006 @ 3:29 pm

    cute travail!entranced ferry:penetration coefficients berated

  7. Denver said,

    January 11, 2007 @ 4:52 am

    Hello! I figured it would be nice if I signed your guestbook. I just thought that I would visit your homepage and see what all you have been up to, well – it’s awesome!

  8. Dental Insurance Coventry said,

    January 11, 2007 @ 11:25 am

    This is one super duper site

RSS feed for comments on this post

Leave a Comment