ScriptSpot home

Forum topic · General Scripting

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

By Michele Marcelli · 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)
Michele Marcelli

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

Panayot Karabakalov

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

Michele Marcelli

Ho yes! it is right! :)

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

mjbg

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

Reply to mjbg
Michele Marcelli

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

Reply to Michele Marcelli
Oleksandr Kramer

Ctrl+n?

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

You now about shortcut Ctrl+n?

Reply to Oleksandr Kramer
Michele Marcelli

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