Skip to content

Instantly share code, notes, and snippets.

@moeinrahimi
Last active January 23, 2019 06:05
Show Gist options
  • Save moeinrahimi/c824b80a421957221c81577f3a1c9054 to your computer and use it in GitHub Desktop.
Save moeinrahimi/c824b80a421957221c81577f3a1c9054 to your computer and use it in GitHub Desktop.
handy regex statements for iran datasets
// اعتبار سنجی شماره همراه
var mobileNumber = '989407422058'
var checkMobile = mobileNumber.match(/0?9[0-9]{9}/i)
/* output
["9893510000", index: 0, input: "989351000000", groups: undefined]
*/
// اعتبار سنجی کد ملی
function isValidIranianNationalCode(input) {
if (!/^\d{10}$/.test(input))
return false;
var check = parseInt(input[9]);
var sum = 0;
var i;
for (i = 0; i < 9; ++i) {
sum += parseInt(input[i]) * (10 - i);
}
sum %= 11;
return (sum < 2 && check == sum) || (sum >= 2 && check + sum == 11);
}
// To be Continued
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment