jQuery-Mask-Plugin 屏蔽电子邮件地址和网址
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/28780184/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
jQuery-Mask-Plugin to mask email addresses and web URL's
提问by prime
I'm using the jQuery-Mask-Pluginin my application and using that I was able to successfully add masks to telephone numbers, date time .. etc.
我在我的应用程序中使用 jQuery-Mask-Plugin并使用它我能够成功地将掩码添加到电话号码、日期时间......等。
$("#date").mask("99/99/9999",{placeholder:"mm/dd/yyyy"});
$("#phone").mask("(999) 999-9999");
But I could not find a way to add masks to email addresses and web site addresses.
但是我找不到向电子邮件地址和网站地址添加掩码的方法。
I know it is some what tricky to identify exact patterns in those but is there any way in jQuery-Mask-Plugin
to do that ?
我知道识别这些中的确切模式有些棘手,但有什么方法jQuery-Mask-Plugin
可以做到这一点吗?
回答by Igor Escobar
There is no such thing as e-mail "mask" because it doesn't have a "fixed" or predictable structure. First, you need to validate your input, always, and that can be done with a simple regexp. Now.. If you want to avoid the user typing things that shouldn't be done you can do this:
没有电子邮件“掩码”这样的东西,因为它没有“固定”或可预测的结构。首先,您需要始终验证您的输入,这可以通过一个简单的正则表达式来完成。现在..如果你想避免用户输入不应该做的事情,你可以这样做:
$('.alpha-no-spaces').mask("A", {
translation: {
"A": { pattern: /[\w@\-.+]/, recursive: true }
}
});
Hope it helps.
希望能帮助到你。