I need a Regular expression for Isracard (Israel Credit Card).
Would be very grateful for help, or maybe for some info how to make it.
Format of Isracard 8-9 digits.
ex. Picture of card - .jpg
I need a Regular expression for Isracard (Israel Credit Card).
Would be very grateful for help, or maybe for some info how to make it.
Format of Isracard 8-9 digits.
ex. Picture of card - http://images.delcampe./img_large/auction/000/157/341/572_001.jpg
Share Improve this question edited May 9, 2017 at 11:16 Ashkan Mobayen Khiabani 34.2k35 gold badges111 silver badges184 bronze badges asked Jul 6, 2016 at 11:28 F. Sv.F. Sv. 617 bronze badges 1- 1 What is the format of Isracard. please add some details – Ashkan Mobayen Khiabani Commented Jul 6, 2016 at 11:33
4 Answers
Reset to default 6I found a validation for IsraCard:
<script>
var cardValid=function(cardNo){
var sum = 0, iNum;
for( var i in cardNo+='' ){
iNum = parseInt(cardNo[i]);
sum += i%2?iNum:iNum>4?iNum*2%10+1:iNum*2;
}
return !(sum%10);
};
</script>
Asp vb script IsraCard Credit Card number Validation (8 or 9 digits)
<%
Function IsraCardCheck(strNumber)
p1 = "987654321"
p2 = strNumber
srez = 0
if len(p2) < 9 then p2 = "0" & p2
for i = 1 to 9
a = mid(p1, i, 1)
b = mid(p2, i, 1)
c = a * b
srez = srez + c
next
if srez mod 11 = 0 then
IsraCheck = true
else
IsraCheck = false
end if
End Function
%>
I just copied the code from there and for more information and details you may want to check the link itself: Anatomy of credit card number formats
Based on what I see here (and without any further guidelines from you on on what an Israel credit card number begins with), this should probably work
(3640|4580)-?([0-9]{4}-?){3}
A simple regex to check if it's a number with 8 or 9 digits:
^[0-9]{8,9}$
Or if a space or dash is allowed between the digits.
^[0-9](?:[ -]?[0-9]){7,8}$
To match for example :
1234-5678-9
1234 5678
1 2 3 4 5 6 7 8 9
1-2-3-4-5-6-7-8
12-34 56-78 9
But a pure regex can't do calculations, like f.e. a modulus check.
So extra code is needed to give a more accurate validation.
Javascript example snippet:
function checkIsracard(creditcardNo){
if(! /^[0-9](?:[ -]?[0-9]){7,8}$/.test(creditcardNo.toString())) return false;
let total = 0;
let cardDigits = creditcardNo.toString().match(/[0-9]/g);
cardDigits.forEach(function(digit, indx){
total += parseInt(digit,10)*(cardDigits.length - indx);
});
return (total%11 === 0);
}
console.log('1234-5678-9:\t'+checkIsracard('1234-5678-9'));
console.log('1234 5679:\t'+checkIsracard('1234 5679'));
console.log('123456789:\t'+checkIsracard(123456789));
console.log('12345679:\t'+checkIsracard(12345679));
console.log('123456781:\t'+checkIsracard('123456781')); // modulus check fail
console.log('12345671:\t'+checkIsracard('12345671')); // modulus check fail
console.log('1234567:\t'+checkIsracard('1234567')); // not enough digits
console.log('1234567890:\t'+checkIsracard('1234567890')); // too many digits
But if the question would be about the 16 digit visa credit card numbers?
For those, the more widely used luhn-algorithm is used.
So that algorithm would be a bit more plicated.
Algorithm explanation: https://web.archive/web/20140227235803/http://povolotski.me/2013/09/24/isracard-credit-card-number-validation-2/
function isracardCheck(num) {
if(typeof num !== 'number') num=''+num;
if(num.length < 8 || num.length > 9) return false;
var sum=0;
num.split('').forEach(function(val,key){
sum+=parseInt(val,10)*(num.length-key);
})
return sum % 11 == 0;
}
License: MIT, https://gist.github./avimar/e7421f96357bf06acc31d952c7baf84e