Reputation: 157
I want to validate a numeric value(with or without decimal point). If I use
textInput.restrict = "0-9.";
it will only restrict to enter a number with 0-9 or '.'(decimal point). But it doesn't restrict to enter double decimal(e.g-123.3.3)which is not a valid number.
So,what should be the regex for such scenario ? Thank you!
Upvotes: 0
Views: 58
Reputation: 28305
To define the regular expression in ActionScript 3.0:
var decimalPattern:RegExp = /^\d+(\.\d+)?$/;
Or, if you prefer:
var decimalPattern:RegExp = new RegExp("^\\d+(\\.\\d+)?$");
This pattern says "some digits, possibly followed by a '.' and more digits".
If you want a more generic solution, with consideration for things like negative numbers and commas (e.g. -13,386.91
), then you could use: http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/validators/NumberValidator.html
Upvotes: 1