Have a string like this: 'XXX-XXX-XXX';
This can be changed by the user.
Than I have another string like this, that uses characters in this string to generate a serial number: 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
This can be changed by the user.
Now, I need to loop through a bunch of input values to determine if they match the formula (will always be only X's and dashes. Note: dashes might not even exist in formula, this is user defined and can change from within a different input field altogether).
Basically, there is another group of input fields:
<div class="check_these">
<input type="text" class="p-serials" name="pserials[]" value="YER-CGH-JOP" />
<input type="text" class="p-serials" name="pserials[]" value="BAB-CC1-D80" />
<input type="text" class="p-serials" name="pserials[]" value="JUQ-P" />
<input type="text" class="p-serials" name="pserials[]" value="XXX-XXX-XXX" />
</div>
So, we have the var formula = 'XXX-XXX-XXX';
variable and the possible characters that are allowed in the string var chrs = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
So, how to change this code below so that it returns only those that match:
var currMatches = $(".p-serials").map(function () {
// Need to match only formula numbers in here!
return $(this).val();
}).get();
So, according to the inputs above,
currMatches should be equal to this: ["YER-CGH-JOP", "XXX-XXX-XXX"]
Since these are the only ones that match the formula and characters allowed.