当输入格式为字符串时:
the beginning
r
orR
, then some non-digit letters, I want to replace the string withR
.
是这样的情况:
onkeyup="this.value=this.value.replace(/^[rR]\D/g,'R')"
但它不起作用。
有人可以帮帮我吗?谢谢。
最佳答案
使用以下正则表达式:
onkeyup="this.value=this.value.replace(/^[rR]\D+/, 'R')";
查看此演示:
<input onkeyup="this.value=this.value.replace(/^[rR]\D+/,'R')" />
关于javascript正则表达式替换输入表单验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32043557/