How can I write ONLY numbers in EditText? (no letters accepted)

Hi All man! :)

My question is simple, but I can not find answer... :(

How can I write ONLY numbers in EditText? In essence, I have to write only numbers and not letters...

Situation:

I write any numbers in editText and I've as result in label (like addition, division ecc).
I write any word or letter and I've as result a messagebox like "You can write only numbers!"

Any help is welcome :)

Thanks
Michele71

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Michele71's picture

WoW! A different way to reach

WoW! A different way to reach the same conclusion! The previous mode was fine, but this is great!

Anubis Thank you so much! :)

P.S: Your answers are never too late ;)

hello

Anubis's picture

or...

fn isNumSeq str = ((trimLeft str "0123456789").count == 0)
 
on edt1 changed txt do
(
	if not isNumSeq txt do
		messagebox "You can write only numbers!"
)

uh, maybe i reply too late :)

my recent MAXScripts RSS (archive here)

Michele71's picture

Ho yes! it is right! :) Very

Ho yes! it is right! :)

Very very thanks!!!!!!!!!

mjbg's picture

this should workon

this should work

on edt1 changed txt do 
(
try(if superclassof (execute edt1.text) != number do messagebox "You can write only numbers!")
catch(messagebox "You can write only numbers!")
)

but i really belive using a spinner would be much better

Michele71's picture

The spinner not good. I'm

The spinner not good. I'm creating a script calculation ;)

Kstudio's picture

Ctrl+n?

>>The spinner not good. I'm creating a script calculation ;)

You now about shortcut Ctrl+n?

Michele71's picture

Course track :) I am

Course track :)

I am preparing a small script which calculates the mass, density and volume of an object, like a small calculator. I would like to speed up the calculation. The real problem is NOT to write letters in dell'Edittext ;)

Thanks anyway for your suggestion

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.