使用 jQuery 或 Zend Form 的电话号码验证器/过滤器?
我正在考虑向 Zend Framework 应用程序的电话号码字段添加一些验证/过滤。不确定这是否是我应该做的事情。
我认为拥有这样的功能可能会对用户有所帮助,这样我就可以强制执行特定的显示格式。我不确定电话号码的格式是否应该存储在数据库中,或者何时从数据库中检索。我不想对此太严格,因为它并不是那么重要。我只是想阻止一半人输入 123.456.7890
作为电话号码格式,而另一半人输入 (123) 456-7890
作为其他格式。我希望电话号码列表看起来一致。那么也许我应该使用一些 JavaScript 来帮助用户输入他们的号码?也许有一个 jQuery 插件已经可以做到这一点,我可以将它与我的 Zend Form 集成?
你怎么认为?
I'm thinking about adding some validation/filtering to the phone number field of my Zend Framework application. Not sure if this is something I should do or not.
I thought it might be helpful for users to have such a feature so I could enforce a particular display format. I'm not sure if the formatting of the phone number should be stored in the database, or when it is retrieved from the database. I don't want to be too strict about this because it's not really that important. I just wanted to prevent half the people from entering 123.456.7890
as their phone number format and the other half entering (123) 456-7890
as the other format. I want the listing of phone numbers to look consistent. So maybe I should use some javascript to help the user enter their number? Maybe there is a jQuery plugin that already does that and I can integrate it with my Zend Form?
What do you think?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我最喜欢的推荐之一:
JQuery 屏蔽输入插件
One of my favorite recommendations:
JQuery Masked Input Plug-in
您仍然希望在后端强制执行验证,因为 JavaScript 验证可以轻松绕过。这是我的验证插件,它强制 +1.1234567890:
如果您搜索电话验证正则表达式,您可以找到任意数量的验证正则表达式,您可以在 preg_match() 中替换您的特定需要。
You will still want to enforce validation on the back end as javascript validation can be bypassed easily. This is my validation plugin which forces +1.1234567890:
If you google phone validation regex you can find any number of validation regular expressions which you can substitute in preg_match() for your particular needs.
您不需要为手机创建自定义验证器。 Zend 有一个使用本地化的电话验证器的提案。虽然尚未准备好,但您可以使用正则表达式验证器:
You dont need to create a custom validator to phones. Zend has a proposal for a phone validator using localization. Whilst not ready yet, you can use the Regex validator: