开发者

As3 input-field number condition

开发者 https://www.devze.com 2023-01-17 20:42 出处:网络
I\'m trying to validate a flash form. In one case I need to know how to check if the value is a number.

I'm trying to validate a flash form. In one case I need to know how to check if the value is a number.

If someone could show me this if-sentence, i would be 开发者_如何学JAVAvery grateful! :)


Use Number to cast a String to a Number and then isNaN to check if the result is a Number:

var str:String="1234";

var n:Number = Number(str);
if (isNaN(n)) {
 trace(str+" is not a number");
} else {
 trace(str+" is a number");
}

str="12a4";
n=Number(str);

if (isNaN(n)) {
 trace(str+" is not a number");
} else {
 trace(str+" is a number");
}
0

精彩评论

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