我正在寻找一个允许插入或注册这些金额
的javascript正则表达式模式import android.app.Activity;
import android.os.Bundle;
import android.webkit.WebView;
public class WebViewActivity extends Activity {
private WebView webView;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.webview);
webView = (WebView) findViewById(R.id.webView1);
webView.getSettings().setJavaScriptEnabled(true);
webView.loadUrl("http://www.google.com");
}
}
但这些数字不应小于0.我设法找到模式,但我想省略“$”。我想要的只是数字,逗号和点数
5
5.1
5.10
5
500,000
500,000.1
500,000.10
答案 0 :(得分:3)
删除\$?
/^\d+(,\d{3})*(\.\d*)?$/
var x = 5000;
var a = "5,000,000"
var y = "$5,,,000,000"
var z = "500,000"
var c = "c231"
var d = "1...0.00"
var e = "..."
var f = "1.00,,,"
var validRegEx = /^\d+(,\d{3})*(\.\d*)?$/;
console.log(x," Valid", validRegEx.test(x))
console.log(a," Valid", validRegEx.test(a))
console.log(y," Valid", validRegEx.test(y))
console.log(z," Valid", validRegEx.test(z))
console.log(c," Valid", validRegEx.test(c))
console.log(d," Valid", validRegEx.test(c))
console.log(e," Valid", validRegEx.test(c))
console.log(f," Valid", validRegEx.test(c))

答案 1 :(得分:0)
根据我对问题的评论,新代码将是
var x = 5000;
var a = "5,000,000"
var y = "$5,,,000,000"
var z = "500,000"
var c = "c231"
console.log(x," Valid", /^\d+(,\d{3})*(\.\d*)?$/.test(x))
console.log(a," Valid", /^\d+(,\d{3})*(\.\d*)?$/.test(a))
console.log(y," Valid", /^\d+(,\d{3})*(\.\d*)?$/.test(y))
console.log(z," Valid", /^\d+(,\d{3})*(\.\d*)?$/.test(z))
console.log(c," Valid", /^\d+(,\d{3})*(\.\d*)?$/.test(c))
答案 2 :(得分:0)
尝试
^\$?([0-9]{1,3},([0-9]{3},)*[0-9]{3}|[0-9]+)(\.[0-9][0-9])?$