电话验证:如何在键入时覆盖文本框中的文本而不清除整个字段?
我想知道如何创建一个脚本来覆盖文本框中已有的文本。 (在 jquery 或 JavaScript 中) 示例:如果我有一个文本电话字段,内容为:
+1 (xxx) xxx-xxxx
当用户单击该字段时,我希望保留这些字符,并将焦点设置为文本框中的第 4 个字符,就在1.
然后,当用户键入每个数字时,它会一一覆盖 x,直到所有 x 都消失。但是,我希望保留括号和连字符格式,以便用户围绕格式输入表单。
我还希望此表单仅允许数字、连字符和括号,并且如果 x 仍然存在则不允许提交。
如果您能帮我解决这个问题,谢谢! :-)
I would like to know how to create a script that overwrites text that is already in a text box. (in jquery or javascript)
Example: If I have a text phone field that says:
+1 (xxx) xxx-xxxx
When a user clicks the field, I want the characters to remain, and the focus set to the 4TH character in the text box, just after the 1.
Then, as a user types each number, it overwrites the x one by one, until all the x's are gone. But, I want the parenthesis and hyphen formatting to stay, so the users input forms around the formatting.
I would also like this form to only allow numbers, hyphens, and parenthesis, and not allow submitting if x's still exist.
If you can help me with this, THANK YOU! :-)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试屏蔽输入插件@[
]< a href="http://digitalbush.com/projects/masked-input-plugin/" rel="nofollow">1
看起来它符合您的需求。
Try masked input plugin @ [
]1
Looks like it matches what you need.