ASP.NET CompareValidator - 确认电子邮件地址 [英] ASP.NET CompareValidator - confirm email address

查看:140
本文介绍了ASP.NET CompareValidator - 确认电子邮件地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用比较验证器验证2个字段

1)电子邮件地址(必填字段 - 使用必填字段验证器)

2)确认电子邮件地址



如果我在确认电子邮件地址的电子邮件地址AND abc@abc.com中输入abc@abc.com,它将正常工作。



但是当我在其中一个文本框中的电子邮件地址后面添加空格时,会说两封电子邮件都不匹配,这是不可取的。怎么解决这个?



如果我能够通知用户电子邮件地址中不允许这样的空间,那将对用户有所帮助。

I want to validate 2 fields using compare validator
1)Email address (required field - used required field validator)
2)Confirm email address

If I enter abc@abc.com in email address AND abc@abc.com in confirm email address, it will work fine.

But when I add space after the email address in one of the textbox, it will say that both emails do not match which is not desirable. How to solve this ?

It would be helpful for the user if I would be able to notify to the user that the space is not allowed in email address.

推荐答案

您可以使用 TrimEnd()方法获取最后一个空格字符:

You can use TrimEnd() method for the last space char:
yourText = yourText.Trim(); //OR
yourText = yourText.TrimEnd();





您可以用替换()方法替换空格,例如:


OR
You can replace the spaces by Replace() method such as:

Text.Replace(" ", string.empty);



但更重要的是你应该使用 FilteredTextBoxExtender 来避免字符例如空间和其他你不希望用户输入的字符。



有关更多信息,请查看AJAX控件工具包'的FilteredTextBoxExtender [ ^ ]。



在invalidchars上使用它。



祝你好运,

OI


But more importantly you should use FilteredTextBoxExtender for avoiding characters such as space and the other chars that you desire not be entered by user.

For more info check AJAX control tool kit''s FilteredTextBoxExtender[^].

Use it on invalidchars.

Good luck,
OI


这篇关于ASP.NET CompareValidator - 确认电子邮件地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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