Kindly note, I tried some suggestions from other SO post about regexp, none helped!!! Coming to the question -
I have JSON data like this (original: https://api.myjson.com/bins/fvzpp):
{
VISA: {
cardPattern: "/^4/",
cardNumberLength: 16,
cvv: "required",
cvvLength: 3,
displayText: "Visa"
},
MASTERCARD: {
cardPattern: "/^5[1-5]/",
cardNumberLength: 16,
cvv: "required",
cvvLength: 3,
displayText: "Master"
},
MAESTRO: {
cardPattern:
"/^(50|63|66|5[6-8]|6[8-9]|600[0-9]|6010|601[2-9]|60[2-9]|61|620|621|6220|6221[0-1])/",
cardNumberLength: 19,
cvv: "optional",
cvvLength: 4,
displayText: "Maestro"
}
}
Please see the cardPattern property which is in string format. How do i make use of the same to test a string(say 445). For example, "/^4/".test(mysttring) does not work. And also var reg = new RegExp("/^4/") returns a weird //^4// which will never match mystring. How to handle such a response for regex? Just to be more explicit, how to handle response['VISA'].cardPattern.test(4545) which should have worked, but does not!
And also, The response is not JSON format, and is object inside object. What is the best way to parse such a response? I tried for-in loop, but that returns 'VISA', 'MASTERCARD' and 'MAESTRO'(the strings) which is not what I want.