/ Published in: ActionScript 3

Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
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);
Comments
