开发者

Actionscript restrict only number with two decimals

why it is not simple!

i just want to restrict input text to allow only number with 2 decimals examples 22.44 10.55 6.00 55.72

how can i make it with actionscript 2.0 ?

bless will raise on t开发者_如何学JAVAhe helper!


Restrict the characters that can be entered into your text field to the numbers 0 to 9 and the decimal point:

textField.restrict = "0-9.";

Then add a listener function to the onChanged event, removing everything beyond two characters from the decimal point, or any second occurrence of ".":

textField.onChanged = function () {
    var ind = textField.text.indexOf (".");
    if ( ind > -1) {
        var decimal = textField.text.substring (ind+1);
        if (decimal.indexOf (".") > -1) {
            textField.text = textField.text.substring (0, ind + 1 + decimal.indexOf("."));
        }
        if (decimal.length > 2) {
            textField.text = textField.text.substring (0, ind + 3);
        }
    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜