Regular Expression Pattern With A Variable
I am using regular expression to check number of digits after decimal. This is working fine when it is used for two or three digits, for example \d{2} or \d{3}, but what if I need
Solution 1:
You can use RegExp, like;
//just an example thoughvar i = 2;
var pattern = newRegExp("\\d{"+i+"}$");
Solution 2:
You can write a function that generates the RegEx string with the parameter you provide for the number or decimal digits you need.
Post a Comment for "Regular Expression Pattern With A Variable"