在C#.net中验证常规格式 [英] validating regular forms in c#.net

查看:64
本文介绍了在C#.net中验证常规格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

先生您好,

我正在C#.NET中进行项目.项目名称为基于缺陷衰减模型的缺陷估计".我以模块身份登录,但如果他是新用户,则必须以注册表格进行注册. fielda作为用户名,密码,conformpassword和电子邮件ID.

我的问题是
所有字段均应强制验证,而FOR Email-id则必须强制验证.和@符号将由用户给出,然后仅当用户单击提交"时,它才必须进入数据库.

请解决我的问题.

Hello sir,

I am doing project in C#.NET The project title is "Estimation of defects based on Defect decay model".I got login as a module but if he is new then he has to register in registration form.In the form i have taken the fielda as username,password,conformpassword and Email-id.

my problem is
All the fields should be validated compulsorly and FOR Email-id compulsorly . and @ symbols are to be given by user then only if user clicks on submit it has to enter database.

plz solve my problem.

推荐答案

您可以使用正则表达式完成.

You can do it using Regular expressions.

using System.Text; 

private bool IsValidEmail(string email)        
{            
    string emailRegEx = @"^[a-z][a-z|0-9|]*([_][a-z|0-9]+)*([.][a-z|"
                      + @"0-9]+([_][a-z|0-9]+)*)?@[a-z][a-z|0-9|]*([-][a-z|0-9]+)*\.([a-z]" 
                      + @"[a-z|0-9]*(\.[a-z][a-z|0-9]*)?)


"; RegularExpressions.Match match = RegularExpressions.Regex.Match(电子邮件,emailRegEx,RegularExpressions.RegexOptions.IgnoreCase); 返回匹配.成功; }
"; RegularExpressions.Match match = RegularExpressions.Regex.Match(email, emailRegEx, RegularExpressions.RegexOptions.IgnoreCase); return match.Success; }



阅读此以获取更多信息:
MSDN:如何:使用正则表达式约束ASP.NET中的输入 [ ^ ]



Read this for more info:
MSDN: How To: Use Regular Expressions to Constrain Input in ASP.NET[^]


使用正则表达式验证器,然后在google上找到正则表达式:)
Use Regular Expression validator and find out the regular expression on google :)


这篇关于在C#.net中验证常规格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆