开发者

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

开发者 https://www.devze.com 2023-01-18 01:15 出处:网络
Only the number and alphabet is allowed to be contained in the input string, return true or false. function is_valid(str:String):Boolean {

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

精彩评论

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