JavaScript Decimal Place Restriction With RegEx

前端 未结 7 915
北恋
北恋 2020-12-06 12:23

I have some client-side validation against a text box, which only allows numbers up to two decimal places with no other input.

This script was a basis for entering n

7条回答
  •  情深已故
    2020-12-06 12:50

    gs: This is very close, but the line

    f.value = f.value.replace(/[^\d\.]/g, "");
    

    Doesn't actually appear to work. In fact I lose focus of the text box for some reason. Although perhaps it's my code ;)

提交回复
热议问题