Skip to content

Instantly share code, notes, and snippets.

@itaymesh
Last active July 16, 2018 06:47
Show Gist options
  • Save itaymesh/3b89f4e40f241efbbe93481d5ee6fbce to your computer and use it in GitHub Desktop.
Save itaymesh/3b89f4e40f241efbbe93481d5ee6fbce to your computer and use it in GitHub Desktop.
<script>
require([
'jquery',
'jquery/ui',
'jquery/validate',
'mage/translate'
], function($){
$.validator.addMethod(
'validate-customer-id-number', function(value) {
var IDnum = String(value);
if ((IDnum.length>9) || (IDnum.length<5))
return false;
if (isNaN(IDnum))
return false;
if (IDnum.length<9)
{
while (IDnum.length<9)
{
IDnum = '0' + IDnum;
}
}
var mone = 0, incNum;
for (var i = 0; i < 9; i ++)
{
incNum = Number(IDnum.charAt(i));
incNum *= (i % 2) + 1;
if (incNum > 9)
incNum -= 9;
mone += incNum;
}
if (mone % 10 == 0)
return true;
else
return false;
}, $.mage.__('Enter Valid Id Number')
)
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment