winform 表单正则表达式验证 示例(ValidationRule)
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors.DXErrorProvider;
using DevExpress.XtraEditors.Controls;
using System.Text.RegularExpressions; namespace DevDemo
{
public partial class LoginForm : Form
{
public LoginForm()
{
InitializeComponent();
InitValidationMode();
} private void InitValidationMode()
{
CustomValidationRule rule = new CustomValidationRule();
rule.ErrorText = "用户登录代码只能是8位长,并且前两位是字符,后面是数字";
rule.ErrorType = ErrorType.Critical;
//绑定验证控件
vpMain.SetValidationRule(txtUserName, rule);
} private void btnLogin_Click(object sender, EventArgs e)
{
vpMain.Validate();
if (txtUserName.Text == "vp123456" && txtPassword.Text == MD5("aaaaaa"))
{
this.Hide();
MainForm m = new MainForm();
m.Show();
}
} private string MD5(string str)
{
return str;
}
} #region CustomValidationRule
// <customTextEdit>
public class CustomValidationRule : ValidationRule
{
public override bool Validate(Control control, object value)
{
string parttern = @"^[\w\W]{2}\d{6}$";
bool res = false;
res = Regex.IsMatch(value.ToString(), parttern);
return res;
}
} #endregion
}
LoginForm.cs
namespace DevDemo
{
partial class LoginForm
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null; /// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
} #region Windows Form Designer generated code /// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.btnLogin = new DevExpress.XtraEditors.SimpleButton();
this.lblUserName = new DevExpress.XtraEditors.LabelControl();
this.lblPassword = new DevExpress.XtraEditors.LabelControl();
this.txtUserName = new DevExpress.XtraEditors.TextEdit();
this.vpMain = new DevExpress.XtraEditors.DXErrorProvider.DXValidationProvider(this.components);
this.txtPassword = new DevExpress.XtraEditors.TextEdit();
((System.ComponentModel.ISupportInitialize)(this.txtUserName.Properties)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.vpMain)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.txtPassword.Properties)).BeginInit();
this.SuspendLayout();
//
// btnLogin
//
this.btnLogin.Location = new System.Drawing.Point(, );
this.btnLogin.Name = "btnLogin";
this.btnLogin.Size = new System.Drawing.Size(, );
this.btnLogin.TabIndex = ;
this.btnLogin.Text = "登录";
this.btnLogin.Click += new System.EventHandler(this.btnLogin_Click);
//
// lblUserName
//
this.lblUserName.Location = new System.Drawing.Point(, );
this.lblUserName.Name = "lblUserName";
this.lblUserName.Size = new System.Drawing.Size(, );
this.lblUserName.TabIndex = ;
this.lblUserName.Text = "用户名";
//
// lblPassword
//
this.lblPassword.Location = new System.Drawing.Point(, );
this.lblPassword.Name = "lblPassword";
this.lblPassword.Size = new System.Drawing.Size(, );
this.lblPassword.TabIndex = ;
this.lblPassword.Text = "密 码";
//
// txtUserName
//
this.vpMain.SetIconAlignment(this.txtUserName, System.Windows.Forms.ErrorIconAlignment.MiddleRight);
this.txtUserName.Location = new System.Drawing.Point(, );
this.txtUserName.Name = "txtUserName";
this.txtUserName.Size = new System.Drawing.Size(, );
this.txtUserName.TabIndex = ;
//
// txtPassword
//
this.vpMain.SetIconAlignment(this.txtPassword, System.Windows.Forms.ErrorIconAlignment.MiddleRight);
this.txtPassword.Location = new System.Drawing.Point(, );
this.txtPassword.Name = "txtPassword";
this.txtPassword.Properties.PasswordChar = '*';
this.txtPassword.Size = new System.Drawing.Size(, );
this.txtPassword.TabIndex = ;
//
// LoginForm
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(, );
this.Controls.Add(this.txtPassword);
this.Controls.Add(this.txtUserName);
this.Controls.Add(this.lblPassword);
this.Controls.Add(this.lblUserName);
this.Controls.Add(this.btnLogin);
this.Name = "LoginForm";
this.Text = "登陆";
((System.ComponentModel.ISupportInitialize)(this.txtUserName.Properties)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.vpMain)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.txtPassword.Properties)).EndInit();
this.ResumeLayout(false);
this.PerformLayout(); } #endregion private DevExpress.XtraEditors.SimpleButton btnLogin;
private DevExpress.XtraEditors.LabelControl lblUserName;
private DevExpress.XtraEditors.LabelControl lblPassword;
private DevExpress.XtraEditors.TextEdit txtUserName;
private DevExpress.XtraEditors.DXErrorProvider.DXValidationProvider vpMain;
private DevExpress.XtraEditors.TextEdit txtPassword;
}
}
LoginForm.Designer.cs
-----------------------------
天王盖地虎小说网:http://www.twgdh.com/
winform 表单正则表达式验证 示例(ValidationRule)的更多相关文章
- thinkPHP 表单自动验证功能
昨天晚上我们老大叫我弄表单自动验证功能,愁了半天借鉴了好多官网的知识,才出来,诶,总之分享一下我自己的成果吧! thinkphp 在Model基类为我们定义了自动验证的函数和正则表达式,我们只需要在对 ...
- thinkphp表单自动验证
ThinkPHP框架表单验证 对注册到test表的表单进行验证 在注册之前要对表单进行验证: 用户名非空验证,两次输入密码必须一致即相等验证,年龄在18~50之间即范围验证,邮箱格式正则验证. 自动验 ...
- aspx中的表单验证 jquery.validate.js 的使用 以及 jquery.validate相关扩展验证(Jquery表单提交验证插件)
这一期我们先讲在aspx中使用 jquery.validate插件进行表单的验证, 关于MVC中使用 validate我们在下一期中再讲 上面是效果,下面来说使用步骤 jQuery.Valid ...
- PHP - 表单与验证
第11章 表单与验证 学习要点: 1.Header()函数 2.接收及验证数据 我们对Web感兴趣,认为它有用的原因是其主要通过基于HTML的表单发布和收集信息的能力.这些表单用来鼓励网站的反馈.进行 ...
- HTML5表单及其验证
随笔- 15 文章- 1 评论- 115 HTML5表单及其验证 HTML表单一直都是Web的核心技术之一,有了它我们才能在Web上进行各种各样的应用.HTML5 Forms新增了许多新控件及其A ...
- HTML的表单初级验证
HTML的表单初级验证 placeholder(提示信息) required(确保不能为空) pattern(正则表达式验证) 1. placeholder(提示信息) 语法: <p>账号 ...
- Go-Web编程_表单_0x02_验证表单的输入
开发Web的一个原则就是,不能信任用户输入的任何信息,所以验证和过滤用户的输入信息就变得非常重要,我们经常会在微博.新闻中听到某某网站被入侵了,存在什么漏洞,这些大多是因为网站对于用户输入的信息没有做 ...
- bootstrap表单带验证
<!DOCTYPE html> <html lang="zh-CN"> <head> <meta charset="utf-8& ...
- easyui表单多重验证,动态设置easyui控件
要实现的功能:在做添加学生信息的时候,利用easyui的验证功能判断 学号是否重复和学号只能为数字 最终效果如下图: 但在做这个的过程中,遇到了一系列的问题: 扩展validatebox的验证方法,最 ...
随机推荐
- [前端 2]常用的JQuery和Dom页面取值与赋值
导读:书到用时方恨少,需要基础知识的时候,才悔恨自己没有总结学习好.前段时间调了好长时间的页面,突然发现自己之前不怎么在意的取值和赋值,真的是自己一个很薄弱的地方,有时候查半天都找不到一个对的,现在用 ...
- PAT1053. Path of Equal Weight
//之前一直尝试用vector存储path,但是每次错误后回退上一级节点时不能争取回退,导致探索路径正确,但是输出不正确,用参数num,标记前一个路径点的位置传递参数,就好多了 //其中在输入时就将后 ...
- pycurl
http://www.cnblogs.com/lonelycatcher/archive/2012/02/09/2344005.html http://ju.outofmemory.cn/entry/ ...
- 【MySQL】binlog_format以及binlog事务记录分析
MySQL官方对于binlog_format参数的说明: http://dev.mysql.com/doc/refman/5.5/en/binary-log-setting.html binlog_f ...
- EnCase v7 could not recognize Chinese character folder names / file names on Linux Platform
Last week my friend brought me an evidence file duplicated from a Linux server, which distribution i ...
- Android IOS WebRTC 音视频开发总结(三五)-- chatroulette介绍
本文主要从技术角度介绍chatroulette,文章来自博客园RTC.Blacker,支持原创,转载请说明出处. 很多人不知道或没用过chatroulette,下面先来张界面截图让大家有个整体了解: ...
- WinForm中使用AnyCAD三维控件 の 初始化
在WinForm中可以方便的集成AnyCAD.Net三维控件,只需要以下几部即可完成. 一.添加DLL程序集 AnyCAD.Foundation.Net.dll AnyCAD.Presentation ...
- AnyCAD三维控件场景节点详解
SceneNode是AnyCAD三维图形平台的AnyViz显示引擎的核心对象之一,只有放在场景管理器(SceneManager)里的节点才能被显示引擎所显示. 1. 节点分类 SceneNode是 ...
- ios球体弹跳游戏源码
一款耐玩的ios游戏源码,画面上有很多小星星,球体落下的时候,你需要在画面上画出一条条的线条让球体弹跳起来然后吃掉小星星,如果没借助球体就失败了.游戏有很多关卡.注意: <ignore_js_o ...
- 一个学生分数表,用sql语句查询出各班级的前三名
昨天去一家公司面试,被这道题难住了,哎,又失去一次好的机会. 回来 之后就再想这个问题 表结构及数据如下: