检查是否在文本框中输入电子邮件 [英] Check if input in textbox is email

查看:172
本文介绍了检查是否在文本框中输入电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图验证是否userinput是(添加成员数据库)的的电子邮件地址。

I am trying to validate if the userinput is an email adress (adding a member to database).

用户将进入文本框的数据,当验证事件被调用;我要检查,如果输入的是一个有效的电子邮件地址。因此,由ATLEAST的@和点(。)的字符串。

The user will enter data in TextBox, when the validating event gets called; I want to check if the input is a valid email adress. So consisting of atleast an @ and a dot(.) in the string.

有没有办法通过代码来做到这一点,或者从MaskedTextBox中口罩?

Is there any way to do this through code, or perhaps with a Mask from the MaskedTextbox?

推荐答案

不要用正则表达式打扰。 这是一个坏主意。

Don't bother with Regex. It's a Bad Idea.

我通常从不的使用异常来控制程序流程,但就个人而言,在这种情况下,我宁愿让谁创造了 MailAddress 类做的工作对我来说:

I normally never use exceptions to control flow in the program, but personally, in this instance, I prefer to let the experts who created the MailAddress class do the work for me:

try
{
    var test = new MailAddress("");
}
catch (FormatException ex)
{
    // wrong format for email
}

这篇关于检查是否在文本框中输入电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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