ScriptSpot

Forum topic · General Scripting

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

By Michele71 · 2011-11-11

Description

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 (7)

Michele71 · 2011-11-11

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

or...

Anubis · 2011-11-11

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 :)

Michele71 · 2011-11-11

Ho yes! it is right! :)

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

this should workon

mjbg · 2011-11-11

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 · 2011-11-11

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

Ctrl+n?

Kstudio · 2011-11-12

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

You now about shortcut Ctrl+n?

Michele71 · 2011-11-12

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