You can use RegExp, like;
//just an example though
var i = 2;
var pattern = new RegExp("\\d{"+i+"}$");
More Related Contents:
- Find list of strings that matches a pattern that start with a special character « and end with a special character »
- Javascript Regex for decimal [duplicate]
- How to replace plain URLs with links?
- Regular expression to get a string between two strings in Javascript
- Regex to get string between curly braces
- Validate phone number with JavaScript
- What is the meaning of the ‘g’ flag in regular expressions?
- What is the difference between RegExp’s exec() function and String’s match() function?
- Is there a version of JavaScript’s String.indexOf() that allows for regular expressions?
- split string only on first instance of specified character
- Remove HTML Tags in Javascript with Regex
- javascript regex split produces too many items
- How to replace last occurrence of characters in a string using javascript
- Validating user’s UTF-8 name in Javascript
- Javascript fuzzy search that makes sense
- regular expression to match exactly 5 digits
- Javascript regular expression to validate URL
- Split a string by whitespace, keeping quoted segments, allowing escaped quotes
- How to wrap part of a text in a node with JavaScript
- Extract all email addresses from bulk text using jquery
- Increment a number in a string in with regex
- Insert space before capital letters
- how to use dotall flag for regex.exec()
- regular expression for finding decimal/float numbers?
- regex pattern to match the end of a string
- How to remove square brackets in string using regex?
- Regular expression with the cyrillic alphabet
- What’s different between Python and Javascript regular expressions?
- Extract keyword from Google search in Javascript
- Regex matching emoticons