如何在sqlser2008,asp.net中验证电子邮件地址

问题描述:



如何在asp.net,Sqlserver中查看@之前的电子邮件地址?



我的表4中的记录sqlserver,



id电子邮件

--------------------

1 test@test.com

2 test1@test.com

3 testr@test.com

4 common @ test.com



现在我尝试使用tests@test.com注册电子邮件ID,不需要检查域名,但我只需要@ char之前。



检查并显示消息此电子邮件ID在asp.net中可用。



请让我知道。



提前谢谢。

Hi,
How to check Email Address of before @ in asp.net,Sqlserver?

My Table 4 records available in sqlserver,

id Email
--------------------
1 test@test.com
2 test1@test.com
3 testr@test.com
4 common@test.com

Now I try to register Email ID with "tests@test.com" and no need to check domain name but i need only before @ char.

Check and display message "This Email id simillarly available in asp.net" .

Please let me know .

Thanks in advance.

你可以使用带有CharIndex函数的子串函数。



类似



You can Use a Substring function with a CharIndex function .

Something like

SELECT SUBSTRING(@email, 1, CHARINDEX('@', @email) - 1)// Need to modify accordingly





并在返回的S上执行相等ubstring(即。 @字符前面的名称)



And perform an equality on the returned Substring ( ie. name before the @ character )


最好采取整个字符串并直接检查。查询看起来像......

Better to take the whole string and check directly. The query would look like...
SELECT count(id)
FROM Users
WHERE Email = @InputEmail



使用 SQLParameter Class - 提供 @InputEmail 值a> [ ^ ]。如果 count 大于0,则记录存在。



否则你需要拆分字符串并将其与电子邮件列进行比较。


Provide the @InputEmail value using SQLParameter Class[^]. If count is greater than 0, then record exists.

Otherwise you need to Split the string and compare it with Email Column.