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;
}
精彩评论