[英]Replacing Characters other than numbers in textbox
I want to allow only numbers(1 to 5), a $(dollar) .(decimal) and '(singlequote) in a textbox. 我只允许在文本框中输入数字(1到5),$(美元),(十进制)和'(单引号)。 I want to do this on keyup event.
我想在keyup事件上执行此操作。 If user types anything other than these character, it should be replaced with a *.
如果用户键入除这些字符以外的任何其他字符,则应将其替换为*。 Please tell how can I do it?
请告诉我该怎么做?
You can strip the string on key-up like this: 您可以像这样在键入时剥离字符串:
$('input[type=text]').keyup(function(){
$(this).val($(this).val().replace(/[^1-5$.']/g, '*'));
});
Keep in mind that you should verify this on the server side (there are a plethora of ways around it on the client side). 请记住,您应该在服务器端对此进行验证(客户端有很多解决方法)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.