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.
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
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.
In the project I'm working on, we do use long
to store the phone number, which personally I do not like.