坑爹代码 | 要不然你说手机号码应该怎么验证嘛!
在现如今的互联网应用中,手机号码已经完全取代电子邮件成为了用户注册账号的唯一标识。而随着移动网络的高速发展,各种前缀的手机号码不断推出,如何验证有效的手机号码就是程序员必须关注的功能点,你说重要吧? 好像没那么重要,你说不重要吧? 一旦程序出错,用户注册不了那就是大事!
所以你怎么看下面这段验证手机号码是否正确的代码呢?
public String validatePhone(String phoneStr) { if (phoneStr != null) { if (phoneStr.length() == 11) { if (isNumeric(phoneStr)) { if (phoneStr.startsWith("130") || phoneStr.startsWith("131") || phoneStr.startsWith("132") || phoneStr.startsWith("134") || phoneStr.startsWith("135") || phoneStr.startsWith("136") || phoneStr.startsWith("137") || phoneStr.startsWith("138") || phoneStr.startsWith("139") || phoneStr.startsWith("140") || phoneStr.startsWith("141") || phoneStr.startsWith("142") || phoneStr.startsWith("144") || phoneStr.startsWith("145") || phoneStr.startsWith("146") || phoneStr.startsWith("147") || phoneStr.startsWith("148") || phoneStr.startsWith("149") || phoneStr.startsWith("150") || phoneStr.startsWith("151") || phoneStr.startsWith("152") || phoneStr.startsWith("154") || phoneStr.startsWith("155") || phoneStr.startsWith("156") || phoneStr.startsWith("157") || phoneStr.startsWith("158") || phoneStr.startsWith("159") || phoneStr.startsWith("170") || phoneStr.startsWith("171") || phoneStr.startsWith("172") || phoneStr.startsWith("174") || phoneStr.startsWith("175") || phoneStr.startsWith("176") || phoneStr.startsWith("177") || phoneStr.startsWith("178") || phoneStr.startsWith("179") || phoneStr.startsWith("180") || phoneStr.startsWith("181") || phoneStr.startsWith("182") || phoneStr.startsWith("184") || phoneStr.startsWith("185") || phoneStr.startsWith("186") || phoneStr.startsWith("187") || phoneStr.startsWith("188") || phoneStr.startsWith("189")) { return "手机号正确"; } else { return "手机号规则错误"; } } else { return "手机号必须为数字"; } } else { return "手机号长度必须为11位"; } } else { return "手机号不能为空"; } }
逻辑好像没有问题,但是真的好啰嗦啊!!!
那么你有更好的方法吗?
请移步下面链接发表评论,领取奖品:
https://gitee.com/oschina/bullshit-codes/blob/master/java/PhoneRuleValidate.java
码云 6 周年,我们正在征集各种坑爹代码,很多奖品等你来拿
详细的参与方法请看 https://gitee.com/oschina/bullshit-codes
------ 分割线 ------
其他坑爹代码吐槽:
低调大师中文资讯倾力打造互联网数据资讯、行业资源、电子商务、移动互联网、网络营销平台。
持续更新报道IT业界、互联网、市场资讯、驱动更新,是最及时权威的产业资讯及硬件资讯报道平台。
转载内容版权归作者及来源网站所有,本站原创内容转载请注明来源。
- 上一篇
Firefox 68 将采用 Microsoft BITS 安装更新
从 Firefox 68 开始,Mozilla 的 Web 浏览器开始使用 Microsoft BITS( Background Intelligent Transfer Service,后台智能传输服务)提供更新,与 Windows Update 使用的技术相同。 随着 Firefox 70 的到来,BITS 不仅仅是浏览器本身的一部分,将与专用的更新代理一起作为代理使用,这样可以更容易地安装更新。 根据 Mozilla 的 Matt Howell 所说,将更新代理与 BITS 结合是为了让连接速度较慢的用户更容易获得最新的更新,如果只是 BITS 意味着只有在运行 Firefox 时才能下载更新。BITS 结合专用更新代理后,可以在后台真正下载这些更新,而不会影响浏览器性能。这将为每个人提供更方便的更新,并减少那些不受当前更新过程支持的用户获得新更新的时间。 根据Kirk Steuber 的意思,允许 Firefox 在没有更新代理的情况下使用 BITS 进行更新,能够更容易地从一种下载机制过渡到另一种机制,而现在 Firefox 将通过内置到二进制文件的接口调用 BITS,这个接...
- 下一篇
OSC「开源好物」正式上线!库存不多,要买尽快
OSC周边商城开业了,我们决定取名为 「开源好物」。 「好物」寓意着“美好、精美的物品”,美好的事物是每个人的追求嘛。 社区这些年推出的周边产品不多,且更多是作为参与活动的奖励赠送给大家。 因此常会有错过或没有参与活动的小伙伴询问能否通过购买的方式获得周边产品。 为了满足大家的需求,我们决定做一次尝试。 现在「开源好物」正式上线了,如果有你喜欢的产品,欢迎购买。 OSC社区出品的第一个自制产品是「红薯」浮雕马克杯,你是否已经拥有一个了呢?如果没有,如果你喜欢的话,那就“动手”吧。 红薯浮雕马克杯 ▲极简设计,专属浮雕>>点击购买 码云T恤 ▲红色Gitee印花元素,极简设计,柔软触感。>>点击购买 码云鼠标垫 ▲码云超大鼠标垫,让码云守护你的代码&桌面。>>点击购买 >>查看更多「开源好物」 目前推出的产品不多,我们会进一步做更多的尝试去丰富产品种类。大家也提供了一些优秀的产品创意,我们会作为参考,推出更多大家喜欢的产品,也欢迎社区的小伙伴多多提供好的 idea,文创类,科技类,生活类等等都可以。 -----------福-利-分...
相关文章
文章评论
共有0条评论来说两句吧...