实用有效性验证类库UtilityValidator0.1 Release

   在实际软件开发中,我们需要对用户输入的数据进行各种形式的有效性验证,
例如:用户名,密码,Email等等。进行有效性验证通常会用到正则表达式,
但正则表达式的编写通常较复杂,如果能将常用的一些验证操作封装成类库
可以方便程序员的开发,于是就有了UtilityValidator0.1的诞生。

下载 UtilityValidator0.1

UtilityValidator0.1提供10个常用验证方法:

 验证是否只含有数字
public static bool isValidOnlyNumber(string strln)

验证是否只含有字母
public static bool isValidOnllyChar(string strln)

验证是否只含有汉字
public static bool isValidOnllyChinese(string strln)
 
验证是否是有效Email
public static bool isValidEmail(string strln)
 
验证是否是有效密码
public static bool isValidPassWord(string strln)

验证是否是有效传真号码
public static bool isValidFax(string strln)

验证是否是有效电话号码
public static bool isValidTel(string strln)

验证是否是有效移动电话号码
public static bool isValidMobil(string strln)

验证是否是有效邮编号码
public static bool isValidZip(string strln)

验证是否是有效日期
public static bool isValidDate(string strln)

代码示例:

//在工程中添加UtilityValidator.Dll的引用,在代码中加入using UtilityValidator;

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using UtilityValidator;

namespace Demo_Validator
{
    
public partial class Form1 : Form
    
{
        
public Form1()
        
{
            InitializeComponent();
        }


        
private void button1_Click(object sender, EventArgs e)
        
{
            
string str = textBox1.Text;
            
if ( Validators.isValidOnlyNumber(str) )
            
{
                MessageBox.Show(
null,"有效",groupBox1.Text,0,MessageBoxIcon.Information);
            }

            
else
            
{
                MessageBox.Show(
null,"无效",groupBox1.Text,0,MessageBoxIcon.Error);
            }

        }
posted @ 2006-12-20 19:31  梦里花落知多少  阅读(1889)  评论(11编辑  收藏  举报