|
Hello, I'm trying to write a script that only accepts numbers typed from the keyboard and not numbers in a text field. Is this possible with unit's javascript. any help is awesome.
(comments are locked)
|
|
I think you're looking for something like this: http://forum.unity3d.com/threads/12341-Validating-user-input Converting that from C# to UnityScript should be fairly straight-forward. -V Thank you, very helpful.
Sep 22 '11 at 02:24 PM
ThumbStorm
(comments are locked)
|
|
While it seem overwhelming at first, Regular Expressions can do all sort of complex string manipulations. You can allow/unallow any kind of 'expressions/pattern' from a string. You'll find lot of documentation and even lots of prepared RegularExpression out there. OR you could manually validate it by comparing each input's character to a AllowedCharacters char array, or something similar. OR you could use string.Replace("a",""); but this is tedious and will leave tons of unexpected characters. Best bet is the Regex :) I did start validating using a char array and it's working well even though I'm sure it's the long work around. The regular expressions does seem overwhelming but the first time trying new code always is so I think I'll give it a shot. I appreciate the feedback!
Sep 22 '11 at 02:27 PM
ThumbStorm
(comments are locked)
|
|
It's definitely possible with JavaScript. Sounds like you don't want to show a TextField, you just want to capture numbers. Can you just do something like this ? ...or am I misinterpreting your question? Would it be possible to omit letters a-z and only accept numbers 1-9 in the input field?
Sep 21 '11 at 07:27 PM
ThumbStorm
(comments are locked)
|
