如何使用ASP.NET MVC实施输入屏蔽 [英] How to implement input masking with ASP.NET MVC

查看:89
本文介绍了如何使用ASP.NET MVC实施输入屏蔽的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用ASP.NET MVC处理表单,并试图找出如何最好地实现输入屏蔽(例如,电话号码或美国邮政编码).对于我应该在模型中使用的数据类型,这里是否有任何公认的方法. 此问题建议将电话号码,并在模型字段上使用DisplayFormat属性,但这似乎与验证冲突.我真的不介意从视图模型中的一种类型转换为数据模型中的另一种类型,但是我想选择一种适合jQuery非侵入式验证的方法.

I'm working on a form with ASP.NET MVC and am trying to figure out how best to implement input masking (e.g. for phone number or US zip code). Are there any commonly accepted approaches here for the data types I should use in my model. This question suggests to use a long for phone number and using a DisplayFormat attribute on the model field but it seems to conflict with validation. I don't really mind converting from one type in my view model to another type in my data models, but would like to chose an approach which sits well with jQuery unobtrusive validation.

推荐答案

我个人喜欢使用屏蔽的输入插件.您在JavaScript中设置了遮罩,因此它并不麻烦,但不使用data-*属性.

I personally like using the Masked Input Plugin. You set up the mask in JavaScript, so it is unobstrusive, but it does not use data-* attributes.

在我正在从事的项目中,我们确实使用long存储电话号码,我个人不喜欢它.

In the project I'm working on, we do use long to store the phone number, which personally I do not like.

这篇关于如何使用ASP.NET MVC实施输入屏蔽的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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