表单提交后如何从输入掩码中删除文字?

发布于 2024-09-15 20:09:58 字数 576 浏览 2 评论 0原文

我在 ASP.NET 3.5 Webform 应用程序中使用 Josh Bush 的 MaskedInput jQuery 插件。

表单提交后如何摆脱代码隐藏文件中的文字?

例如:带有掩码的电话输入 $("#txtPhone").mask("(99)9999-9999");

在代码隐藏中:

string customerPhone = txtPhone.Text

返回我: (12 )3456-7890

但这就是我想要的: 1234567890

插件更改日志页面 它说我可以使用不带参数的 mask() 方法来实现此目的。但是如何从代码隐藏中做到这一点?

编辑

我的问题不清楚,所以:我想将未屏蔽的值发送到服务器。怎么做呢?

I'm using Josh Bush's MaskedInput plugin for jQuery in an ASP.NET 3.5 Webform app.

How to get rid from the literals in the code-behind file after form submit?

E.g: a phone input with the mask $("#txtPhone").mask("(99)9999-9999");

In the code-behind:

string customerPhone = txtPhone.Text

Which returns me: (12)3456-7890

But this is what I want: 1234567890

In the plugins changelog page it says I can use mask() method with no arguments to archieve this. But how to do it from the code-behind?!

EDIT

My question wasn't clear, so: I want to send to the server the unmasked value. How to do that?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

夜访吸血鬼 2024-09-22 20:09:59
customerPhone = new string(customerPhone.ToCharArray()
                             .Where(c => char.IsDigit(c)).ToArray());
customerPhone = new string(customerPhone.ToCharArray()
                             .Where(c => char.IsDigit(c)).ToArray());
謸气贵蔟 2024-09-22 20:09:59

我现在正在做的是,使用 submitHandler (验证插件)重置输入值,如下所示:

submitHandler: function(form) {
    $("#txtPhone").val($("#txtPhone").mask());
    form.submit();
},

这解决了问题但是闻起来真的很糟糕......

What I'm doing right now is, using the submitHandler (Validation plugin) to reset the input value, like this:

submitHandler: function(form) {
    $("#txtPhone").val($("#txtPhone").mask());
    form.submit();
},

This solves the problem BUT smells really bad...

输什么也不输骨气 2024-09-22 20:09:59

您可以使用 .NET 中的正则表达式去除非数字字符,如下所示:

customerPhone = Regex.Replace(customerPhone, "[^0-9]", "");

You can strip out non-numeric characters with Regular Expressions in .NET, like this:

customerPhone = Regex.Replace(customerPhone, "[^0-9]", "");
长梦不多时 2024-09-22 20:09:58

初始化 inputmask 时将removeMaskOnSubmit 设置为 true

    $("#txtPhone").inputmask({removeMaskOnSubmit: true});

或者我们可以使用此方法获取未屏蔽的值

$("#txtPhone").inputmask('unmaskedvalue');

Set removeMaskOnSubmit as true when you initialize the inputmask

    $("#txtPhone").inputmask({removeMaskOnSubmit: true});

Or we can get the unmasked value using this

$("#txtPhone").inputmask('unmaskedvalue');
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文