为什么80%的码农都做不了架构师?>>>   

PHP 代码如下:

//   ValidateABN
//     Checks ABN for validity using the published
//     ABN checksum algorithm.
//
//     Returns: true if the ABN is valid, false otherwise.
//      Source: http://www.clearwater.com.au/code
//      Author: Guy Carpenter
//     License: The author claims no rights to this code.
//              Use it as you wish.function ValidateABN($abn)
{$weights = array(10, 1, 3, 5, 7, 9, 11, 13, 15, 17, 19);// strip anything other than digits$abn = preg_replace("/[^\d]/","",$abn);// check length is 11 digitsif (strlen($abn)==11) {// apply ato check method $sum = 0;foreach ($weights as $position=>$weight) {$digit = $abn[$position] - ($position ? 0 : 1);$sum += $weight * $digit;}return ($sum % 89)==0;} return false;
}

JavaScript 代码如下:

function checkABN(str) {if (!str || str.length !== 11) {return false;}var weights = [10, 1, 3, 5, 7, 9, 11, 13, 15, 17, 19],checksum = str.split('').map(Number).reduce(function(total, digit, index) {if (!index) {digit--;}return total + (digit * weights[index]);},0);if (!checksum || checksum % 89 !== 0) {return false;}return true;
}

C# 代码如下:

public static bool ValidateABN(string abn)
{bool isValid = false;int[] weight = { 10, 1, 3, 5, 7, 9, 11, 13, 15, 17, 19 };int weightedSum = 0;//ABN must not contain spaces, comma's or hypensabn = StripNonDigitData(abn);//ABN must be 11 digits long  if (!string.IsNullOrEmpty(abn) & Regex.IsMatch(abn, "^\\d{11}$")){//Rules: 1,2,3  for (int i = 0; i <= weight.Length - 1; i++){weightedSum += (int.Parse(abn[i].ToString()) - ((i == 0 ? 1 : 0))) * weight[i];}//Rules: 4,5  return ((weightedSum % 89) == 0);}return isValid;
}public static string StripNonDigitData(string input)
{StringBuilder output = new StringBuilder("");foreach (char c in input){if (char.IsDigit(c)){output.Append(c);}}return output.ToString();
}

ABNLookup 查询(需要去 https://abr.business.gov.au/Documentation/WebServiceRegistration 注册一个账号,如果成功,会在5天内收到一封邮件,里面有个GUID),PHP 代码:

<?phpnamespace PPost\Library;class ABNLookup extends \SoapClient{private $guid = "xxxxxxxxxxxxxxxxxx";    // guidpublic function __construct(){$params = array('soap_version' => SOAP_1_1,'exceptions' => true,'trace' => 1,'cache_wsdl' => WSDL_CACHE_NONE); parent::__construct('http://abr.business.gov.au/abrxmlsearch/ABRXMLSearch.asmx?WSDL', $params);}public function searchByAbn($abn, $historical = 'N'){$params = new \stdClass();$params->searchString                = $abn;$params->includeHistoricalDetails    = $historical;$params->authenticationGuid            = $this->guid;return $this->ABRSearchByABN($params);}
}
<?phpnamespace PPost\Infrastructure\Helper;class ABNHelper
{public static function ValidateABN($abn){$weights = array(10, 1, 3, 5, 7, 9, 11, 13, 15, 17, 19);// strip anything other than digits$abn = preg_replace("/[^\d]/","",$abn);// check length is 11 digitsif (strlen($abn)==11) {// apply ato check method$sum = 0;foreach ($weights as $position=>$weight) {$digit = $abn[$position] - ($position ? 0 : 1);$sum += $weight * $digit;}return ($sum % 89)==0;}return false;}public static function ABNLookup($abn){try{$abnLookup = new \PPost\Library\ABNLookup();try{$result = $abnLookup->searchByAbn($abn);var_dump($result);//return $result->ABRPayloadSearchResults->response;return $result;} catch    (Exception $e){throw $e;}} catch(Exception $e){throw $e;}}
}

转载于:https://my.oschina.net/u/943746/blog/1832926

【HAVENT原创】Australian Business Number (ABN) 验证相关推荐

  1. 【HAVENT原创】Node Express API 通用配置

    为什么80%的码农都做不了架构师?>>>    ( 基于 Express 4.x ) 启动文件 /app.js: var express = require('express'); ...

  2. 【原创】极验滑块验证:AST还原混淆JS

    本文仅供学习交流使用,如侵立删! 极验滑块验证:AST还原混淆JS 操作环境 win10 . mac node14.17 v_jstools reres 分析 极验验证测试:aHR0cHM6Ly93d ...

  3. 【HAVENT原创】Firebase 定时任务遍历删除子节点

    为什么80%的码农都做不了架构师?>>>    每周定时执行,遍历 Firebase 数据库,删除过期的节点: var config = require('./config.json ...

  4. 【HAVENT原创】JS 屏蔽/禁止双击选中文字

    为什么80%的码农都做不了架构师?>>>    源码如下: <div onselectstart="return false;" ><span& ...

  5. tp剩余未验证内容-8

    模型类的自动验证? 分为自动验证, 和 动态验证(手工验证), 前者的验证规则是定义在模型类中的, 所以要自己创建 扩展的/继承的模型类, 同时用 D方法实例化模型类 而动态验证是 先调用 valid ...

  6. VUE el-input正则验证

    ①只能输入大于0的整数 check(value) {let reg = /^[1-9]\d*$/;var _this = this;if (value) {if (new RegExp(reg).te ...

  7. EasyUI中Validatebox验证框的简单使用

    场景 效果 属性 名称 类型 描述 默认值 required boolean 定义是否字段应被输入. false validType string,array 定义字段的验证类型,比如 email.u ...

  8. jQuery学习之:Validation表单验证插件

    http://polaris.blog.51cto.com/1146394/258781/ 最近由于公司决定使用AJAX + Struts2来重构项目,让我仔细研究一下这两个,然后集中给同事讲讲,让每 ...

  9. TP5 验证-内置规则

    系统内置的验证规则如下: 格式验证类 require 验证某个字段必须,例如: 'name'=>'require' number 或者 integer 验证某个字段的值是否为数字(采用filte ...

最新文章

  1. php拍照从手机相册中选择,微信js-sdk预览图片接口及从拍照或手机相册中选图接口用法示例...
  2. x-manager 管理 kvm虚拟机
  3. 远程线程注入引出的问题
  4. android鼠标dpi,对Android 中 px、DPI、dp(dip)、density的理解
  5. android 之UI 高级控件Adapter(适配器详解)
  6. 手机投电脑_这七个电脑软件,用过的才知道多好用!
  7. 转:WinForm程序中两份mdf文件问题的解决方法
  8. Android之jni编译出现no matching function for call to ‘_JNIEnv::GetJava(JNIEnv* , Java VM**)‘解决办法)‘
  9. JQUERY学习第二天之制作横纵向导航菜单
  10. Binary Tree Preorder Traversal @leetcode
  11. datetime类型保存的时间比实际时间少8小时
  12. R语言包下载(转载)
  13. 【ViPER音效插件】,完美提升电脑音乐播放效果
  14. 网页内容变化监控提醒
  15. win7下安装最新版nodejs16.4.0
  16. win7 桌面html,极品壁纸再一张:Windows7桌面就是我的家
  17. Java使用纯真IP库获取IP对应省份和城市
  18. 介绍一个免费的开源网站(BootCDN)
  19. DApp 上线 BitPortal币通钱包申请指南
  20. 怎样防止租用服务器数据丢失问题

热门文章

  1. 前端面试常问的题目(持续更新中)
  2. 单相在线式不间断电源(B 题)--2020 年TI 杯大学生电子设计竞赛
  3. xftp无法连接windows服务器
  4. Java从IoC到注解开发(1)
  5. ADB+Python+STM32 实现 微信跳一跳辅助
  6. 传统运维必会工具:zabbix监控
  7. ERP专业词汇大放送
  8. springboot缓存管理器(CacheManager)
  9. win10系统,全球第一谷歌Chrome如何改善电池续航?
  10. Angular 5 最新官方demo