Javascript RegEx partial match

后端 未结 6 1850
轮回少年
轮回少年 2021-01-04 03:20

I have a regular expression pattern, which validates for a three digit number

/^\\d{3}$/.test(\"123\")   // true
/^\\d{3}$/.test(\"123.\")  // false
<         


        
6条回答
  •  抹茶落季
    2021-01-04 03:46

    You would be better off by using a library like maskedinput.js. You can then setup your text input like follows:

    jQuery(function($){
        $("#your_input").mask("999");
    });
    

    UPDATE

    you can use a validator for forms and preset specific types of fields to validate

提交回复
热议问题