我有以下表达,
var exp = new RegExp('^[a-zA-Z0-9]' + getMinMax() + '$');
我getMinMax()
的函数动态返回值例如 {2,5} 等!
但它返回一个异常,它表示正则表达式中的语法错误。我该如何纠正?
function getMinMax() {
var minLength = Rule.MinimumLength,maxLength = Rule.MaximumLengh;
var limitExpression = (minLength != 'undefined' && minLength != null ) ? minLength.toString() : '';
limitExpression = (maxLength != 'undefined' && maxLength != null ) ? (limitExpression != '' && limitExpression != null) ? ('{' + limitExpression + ',' + maxLength.toString() + '}') : ('{' + maxLength.toString() + '}') : '';
return limitExpression;
}