7

I have a TextInput field that should be restricted to either capital letters, lowercase letters, numbers and underscores. This is the code I'm trying to use to restrict characters:

restrict="\\A-Z\\a-z\\0-9\\ \\_\\-"

I'm using MXML for this Textinput component.

Unfortunately this does not restrict the \ character, which is the last character I'd like to restrict.

How can I add the backslash to the list of restricted characters?

Thanks

Stephen

Rahil Wazir
  • 10,007
  • 11
  • 42
  • 64
StephenAdams
  • 521
  • 2
  • 9
  • 26

1 Answers1

7

Actually found the solution I've amended the restrict code to:

restrict="A-Za-z0-9 _\-"

I took out all the back slashes which I thought or was using as delimiters.

Works fine now.

pixel
  • 24,905
  • 36
  • 149
  • 251
StephenAdams
  • 521
  • 2
  • 9
  • 26
  • Go ahead and accept your own answer! However, before you do, it looks like you've accidentally left the backslashes in in your revised code. – Stephen Rudolph Jan 16 '12 at 16:10
  • 1
    Yes, the answer should read: restrict="A-Za-z0-9 _\-". The last backslash escapes the dash character which if not escaped specifies a range (e.g. A-Z) – Phil Apr 11 '12 at 12:08
  • 1
    Note that if you are specifying restrict in ActionScript, you need a double-backslash. Like so: `myTextInput.restrict="A-Za-z0-9 _\\-"` – Steven Oct 26 '12 at 17:21