views:

19

answers:

1

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

+3  A: 

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;
}
Stiggler
It may be worth mentioning that that regular expression will only allow numbers and the English alphabet, not characters like ñ, ü or ö.
Lars