1

I'm currently working on a project in which I need to fetch street/city details from a DB using a zipcode. Dutch zipcodes use a "1111 AA" format, I would like to have this entered in a single input field while automatically adding the space in between the numbers and letters if the user doesn't enter the space himself.

I've been googling this quite a bit and all I have been able to find so far were ways of restricting the user input to numeric characters.

Thank you.

4

2 回答 2

0

你需要 JavaScript 来做到这一点。在这种情况下,jQuery 实际上可以帮到你很多。这是一个简洁的插件来处理你想要的:

于 2012-10-04T16:48:10.300 回答
0

HTML 中没有用于此类操作的工具。您可以在 JavaScript 中编写功能,使用处理的按键事件来检查是否输入了四个连续数字并在肯定的情况下附加一个空格。如果您考虑如果用户按下删除键删除字符会发生什么,这将变得更加困难。您还会遇到用户可能会按空格键键入“1111 AA”的问题,然后会发生什么?

所以它的用处值得怀疑。最好只接受带空格和不带空格的邮政编码。

于 2012-10-04T17:11:53.213 回答