繁体   English   中英

正则表达式允许 + 在开头和数字

[英]Regular expression to allow + at the start and digits

我有这个代码。 我如何将其更改为仅允许数字和 + 在开始时。

$(document).on("input", ".numeric>input , .numeric", function() {
    this.value = this.value.replace(/[^0-9\.]/g,'');
});

让我知道,非常感谢!

您可以轻松地将 + 添加为第一个数字,据我了解您正在尝试匹配电话号码,您的代码必须如下所示:

$(document).on("input", ".numeric>input , .numeric", function() {
    this.value = this.value.replace(/[+0-9\.]/g,'');
});

这是一个漂亮的在线工具,您可以在其中轻松构建它们,您不必记住所有内容:

正则表达式

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM