<input type="text" id="price" />
$('#price').keyup(function(){
$('#price').val($('#price').val().replace(',', '.'));
})演示:http://jsfiddle.net/2KRHh/1/
这将用.替换,。这是可以的,但我想用NULL替换所有不是数字的字符。如何使用正则表达式执行此操作?
发布于 2013-06-16 03:39:22
你可能想看看my jQuery iMask plugin,尽管你特别想要的是:
.replace( /.*?(\d+)(?:\.(\d{1,2}))?.*/, function( rx, dollars, cents ){
cents = +( cents || 0 );
return (+dollars + (cents/((cents<10)?10:100))).toFixed(2);
} );如果您只想剥离非数字:
.replace( /[^0-9.]/g, '' )https://stackoverflow.com/questions/17127217
复制相似问题