开发者

actionscript: how to write a function to judge the input string contains only number and alphabet?

Only the number and alphabet is allowed to be contained in the input string, return true or false.

function is_valid(str:String):Boolean { }

My implementation is dumb, as I want to iterate each character.

开发者_如何学编程

Input: akjd8899kdjfj2kj return: true Input: kjd^kdjf^%%$ return: false


Do it with a regular expression:

function isValid(value:String):Boolean
{
   var result:String = value.match(/[0-9a-zA-Z]*/)[0];

   return value.length == result.length;
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜