[英]javascript regular expression replace in input form validation
When inputting a string with a format: 输入格式为的字符串时:
the beginning
r
orR
, then some non-digit letters, I want to replace the string withR
. 开头r
或R
,然后是一些非数字字母,我想用R
替换字符串。
It's in this situation: 正是在这种情况下:
onkeyup="this.value=this.value.replace(/^[rR]\D/g,'R')"
But it does not work. 但它不起作用。
Somebody can help me out? 有人可以帮帮我吗? Thanks. 谢谢。
Use the following regex: 使用以下正则表达式:
onkeyup="this.value=this.value.replace(/^[rR]\D+/, 'R')";
See this DEMO: 看这个演示:
<input onkeyup="this.value=this.value.replace(/^[rR]\\D+/,'R')" />
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.