i have code snippet , avoided repeating of 2 regular expression in if condition because can see differs in 1 digit.
'phonenumberregexp': function (phonecode, homenumber) { if (phonecode === 372) { return /[\s]*^\s*(\d[\s\-\u00b7]*){6,13}$/.test(homenumber); } else { return /[\s]*^\s*(\d[\s\-\u00b7]*){8,13}$/.test(homenumber); } }
any idea how done?
thank in advance
if want can create dynamic regex , use it
'phonenumberregexp': function (phonecode, homenumber) { return new regexp('[\\s]*^\\s*(\\d[\\s\\-\\u00b7]*){' + (phonecode === 372 ? 6 : 8) + ',13}$').test(homenumber); }
Comments
Post a Comment