Return to Snippet

Revision: 41490
at February 18, 2011 22:19 by weavermedia


Initial Code
var s:String = "dog123";
var regNum:RegExp = /[0-9]/;

trace ("String: "+s);

// one-off check using the 'new RegExp' class
trace("Char 2 is a letter = "+(new RegExp("[A-Za-z]")).test(s.substr(1,1)));

// looped check using RegExp var created above
for (var i:int=0; i<s.length; i++)
{
	trace("Char "+(String(i+1))+" is a number = "+regNum.test(s.substr(i,1)));
}

// set a boolean with the result of the RegExp test
var stringIsNumber:Boolean = new RegExp("[0-9]").test(new String("A"));
trace("'A' is a number = "+stringIsNumber);

Initial URL

                                

Initial Description

                                

Initial Title
AS3 check for numbers and letters with RegExp

Initial Tags

                                

Initial Language
ActionScript 3