• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Check if it is a number
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Check if it is a number


  • Subject: Re: Check if it is a number
  • From: Paul Skinner <email@hidden>
  • Date: Sat, 30 Nov 2002 11:46:01 -0500

On Wednesday, November 27, 2002, at 05:19 PM, Thomas wrote:

Hi all, I have a string like this one "12A4B5" and I want to check for each text item if this is a number and do something or if this not a number and do another thing.
Is there a better way than using a try block to check if the current text item is a number ?
Currently I'm using this method :

set my_text to "12A4B5"
repeat with from 1 to count of my_text
set current_item to item i of my_text
try
current_item as number
--this is a number
on error
--this is not a number
end

Thanks Thomas

It isn't clear what you want to do. If you want to do something to the characters that fail, or remove them, then you need to loop through them. If you just want to check that your input is composed of digits and doesn't contain -,+, or spaces you could...

NumeralsOnly("12A4B5")-->false

on NumeralsOnly(n)
try
n as number
return n does not contain "-" and n does not contain "+" and n does not contain " " and n is not ""
on error
return false
end try
end NumeralsOnly

--
Paul Skinner
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.

  • Follow-Ups:
    • Re: Check if it is a number
      • From: Thomas <email@hidden>
References: 
 >Check if it is a number (From: Thomas <email@hidden>)

  • Prev by Date: chance to speak to a MUG about AppleScript
  • Next by Date: Re: Check if it is a number
  • Previous by thread: Re: Check if it is a number
  • Next by thread: Re: Check if it is a number
  • Index(es):
    • Date
    • Thread