C#正则表达式实例

None.gif private   void  okButton_Click( object  sender, System.EventArgs e)
ExpandedBlockStart.gifContractedBlock.gif        
dot.gif {
InBlock.gif            
if(lastTextBox.Text==""|| firstTextBox.Text==""||this.addressTextBox.Text==""|| this.cityTextBox.Text==""||this.stateTextBox.Text==""|| this.zipTextBox.Text==""||this.phoneTextBox.Text=="")
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                MessageBox.Show(
"请输入所有资料信息","错误",MessageBoxButtons.OK,MessageBoxIcon.Error);
InBlock.gif                
this.lastTextBox.Focus();
InBlock.gif                
return;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
if(!Regex.Match(this.lastTextBox.Text,@"^[A-Z][a-zA-Z]*$").Success)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                MessageBox.Show(
"重新输入名字","message",MessageBoxButtons.OK,MessageBoxIcon.Error);
InBlock.gif                
this.lastTextBox.Focus();
InBlock.gif                
return;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
if(!Regex.Match(this.firstTextBox.Text,@"^[A-Z][a-zA-Z]*$").Success)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                MessageBox.Show(
"重输入姓","message",MessageBoxButtons.OK,MessageBoxIcon.Error);
InBlock.gif                
this.firstTextBox.Focus();
InBlock.gif                
return;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
//if(!Regex.Match(this.addressTextBox.Text,@"^[0-9] + \s + ([a-zA-Z] +|[a-zA-Z] + \s[a-zA-Z]+)$").Success)
InBlock.gif
            if(!Regex.Match(this.addressTextBox.Text,@"^[a-zA-Z] +[a-zA-Z] + \s[a-zA-Z]$").Success)
InBlock.gif            
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                MessageBox.Show(
"invalid 重新输入地址","message",MessageBoxButtons.OK,MessageBoxIcon.Error);
InBlock.gif                
this.addressTextBox.Focus();
InBlock.gif                
return;
InBlock.gif
ExpandedSubBlockEnd.gif            }

InBlock.gif            
if(!Regex.Match(this.cityTextBox.Text,@"^([a-zA-Z]+|[a-zA-Z]+\s[a-zA-Z]+)$").Success)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                MessageBox.Show(
"invalid city 城市","message",MessageBoxButtons.OK,MessageBoxIcon.Error);
InBlock.gif                
this.cityTextBox.Focus();
InBlock.gif                
return;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
if(!Regex.Match(this.stateTextBox.Text,@"^([a-zA-Z]+|[a-zA-Z]+\s[a-zA-Z]+)$").Success)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                MessageBox.Show(
"invalid state国家","message",MessageBoxButtons.OK,MessageBoxIcon.Error);
InBlock.gif                
this.cityTextBox.Focus();
InBlock.gif                
return;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
if(!Regex.Match(this.zipTextBox.Text,@"^\d{6}$").Success)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                MessageBox.Show(
"invalid zip邮码","message",MessageBoxButtons.OK,MessageBoxIcon.Error);
InBlock.gif                
this.zipTextBox.Focus();
InBlock.gif                    
return;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
if(!Regex.Match(this.phoneTextBox.Text,@"^[0-9]\d{3}-[1-9]\d{3}-\d{3,4}$").Success)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                MessageBox.Show(
"invalid phone电话号码","message",MessageBoxButtons.OK,MessageBoxIcon.Error);
InBlock.gif                
this.phoneTextBox.Focus();
InBlock.gif                
return;
ExpandedSubBlockEnd.gif            }
  //[\\w-]+(\\.[\\w-]+)*@[\\w-]+(\\.[\\w-]+)+
InBlock.gif
            if(!Regex.Match(this.emailTextBox.Text,@"^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$").Success)  //  \w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*
ExpandedSubBlockStart.gifContractedSubBlock.gif
            dot.gif{
InBlock.gif                MessageBox.Show(
"invalid email 邮箱","message",MessageBoxButtons.OK,MessageBoxIcon.Error);
InBlock.gif                
this.emailTextBox.Focus();
InBlock.gif                
return;
ExpandedSubBlockEnd.gif            }
 //^[a-zA-z]+://匹配(\w+(-\w+)*)(\.(\w+(-\w+)*))*(\?\S*)?$
InBlock.gif
            if(!Regex.Match(this.websiteTextBox.Text,@"^http://([\w-]+\.)+[\w-]+(/[\w- ./?%&=]*)?$").Success)  //http://([\w-]+\.)+[\w-]+(/[\w- ./?%&=]*)?
ExpandedSubBlockStart.gifContractedSubBlock.gif
            dot.gif{
InBlock.gif                MessageBox.Show(
"invalid webSite 网址","message",MessageBoxButtons.OK,MessageBoxIcon.Error);
InBlock.gif                
this.websiteTextBox.Focus();
InBlock.gif                
return;
ExpandedSubBlockEnd.gif            }

InBlock.gif            MessageBox.Show(
"thank you!","geoVi studio",MessageBoxButtons.OK,MessageBoxIcon.Information);
InBlock.gif            Application.Exit();
//处理消息之后关闭所有的程序。
ExpandedBlockEnd.gif
        }

None.gif
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值