actionscript3 中数值(带或不带小数点)的正则表达式是什么

What will be the Regular Expression for Numeric Value(with or without decimal) in actionscript3

我想验证一个数值(带或不带小数点)。 如果我使用

textInput.restrict = "0-9.";

只会限制输入0-9或'.'(小数点)的数字。 但不限制输入双位小数(例如123.3.3),这不是一个有效的数字。

那么,这种情况下的正则表达式应该是什么? 谢谢!

要在 ActionScript 3.0 中定义正则表达式:

var decimalPattern:RegExp = /^\d+(\.\d+)?$/;

或者,如果您愿意:

var decimalPattern:RegExp = new RegExp("^\d+(\.\d+)?$");

这个模式表示 "some digits, possibly followed by a '.' and more digits"。

如果你想要一个更通用的解决方案,考虑到负数和逗号(例如 -13,386.91),那么你可以使用:http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/validators/NumberValidator.html