开发者

parseInt blank field

I'm writing an age verification actionscript for a flash project. Right now I have it where if the user is born before a certain year it will allow them to access the swf if not it will deny them. the problem is if they leave the field blank it wi开发者_如何学Cll allow them access (i'm assuming because a blank field qualifies it as acceptable to the parseInt) so i'm curious as to how to block it so if someone doesn't enter a year it will disallow them from access the swf. here's my code for it

agetext._visible = false; verify_btn.onRelease = function () { if (parseInt(year.text)<=1992){ _root.age._visible = false; }

else { agetext._visible = true; };


If parseInt can't parse a valid Number, it will return NaN (Not a Number). You can check for this by using isNaN:

// check that year is not NaN and is <= 1992
var birthyear = parseInt(year.text);
if (!isNaN(birthyear) && parseInt(birthyear)<=1992) {

Alternatively, you can check to be sure that the TextField isn't blank:

if(year.text != null && year.text != "" && parseInt(year.text) <= 1992) {
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜