I want to verify if a value checks one of following formats : ..A , B.. , A..B
and also retrieve the values: (null, A) , (B, null) , (A, B)
This is my code:
var regexRange = new RegExp("^([a-zA-Z0-9]+)\.\.([a-zA-Z0-9]*)$|^[a-zA-Z0-9]*\.\.([a-zA-Z0-9]+)$");
function getRangeValues(value) {
var from = null;
var to = null;
var matches = regexRange.exec(value);
if (matches !== null) {
if (matches[3] !== undefined) {
to = matches[3];
}
else if(matches[1]!==undefined && matches[1]!=='') {
from = matches[1];
if (matches[2] !== undefined && matches[2] !== '') {
to = matches[2];
}
}
}
var range = { From: from, To: to };
return range;
}
Value: 1233 => From=12, To=null
I don't understand why i get this incorrect behavior, for other use cases it seems to work.