Regular Expression Pattern With A Variable

后端 未结 4 1866
有刺的猬
有刺的猬 2020-11-30 15:11

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}

相关标签:
4条回答
  • 2020-11-30 15:48

    You can write a function that generates the RegEx string with the parameter you provide for the number or decimal digits you need.

    0 讨论(0)
  • 2020-11-30 15:48

    This might be useful : 10+ Useful JavaScript Regular Expression Functions to improve your web applications efficiency

    0 讨论(0)
  • 2020-11-30 16:04

    What about just defining the range of the digits: \d{2,3}?

    0 讨论(0)
  • 2020-11-30 16:07

    You can use RegExp, like;

    
    //just an example though
    var i = 2;
    var pattern = new RegExp("\\d{"+i+"}$");
    
    
    0 讨论(0)
提交回复
热议问题