in action script var x:String="123abc"
i have to check any character is there in that string i.e here abc is that string so i give alert that ....i was trying to say that a string variable but that can contain only numbers
views:
28answers:
3
+1
A:
Do you mean to say that you would like to dispatch an alert if a string contains letters
var testVar:String = '123abc';
var pattern:RegExp = /[a-zA-Z]/g;
if( testVar.search(pattern) == -1 )
{
//all good there's no letters in here
}
else
{
//Alert, alert, letter detected!
}
the "pattern" variable is a RegularExpression that's adaptable. Here I'm only checking for letters... If you need more control, get more info about RegularExpressions or come back here with the specific filter you'd like to implement.
PatrickS
2010-08-18 13:49:10
A:
If the user is inputting text via a TextField
then you can set the restrict
property to limit the characters that can be entered into the textfield:
textFieldInstance.restrict = "0-9";
TextField.restrict documentation:
http://livedocs.adobe.com/flex/3/langref/flash/text/TextField.html#restrict
Sly_cardinal
2010-08-20 01:38:14