Mailing Lists: Apple Mailing Lists
Image of Mac OS face in stamp
Re: Validating email address
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Validating email address



Bernardo H?hl wrote:

>Ol· Michael, tubo bem aqui, obrigado por escrever em portuguÍs.
>
>Thanks for posting.
>
>I tried not to put into my first post unneeded details, but I am
>building an AppleScript Studio application, so I would prefer to use
>plain vanilla applescript function (handler) instead of having to use
>another app, such as "TextCommands".

Use 'do shell script' to call into Perl/Python and use their regex support then. (Note that TextCommands' "check" command is itself just a wrapper around Python's built-in string method and re module.) You have to futz around yourself to keep right on text encodings, of course, and you've the usual limits on the amount of data you can pass on a shell command (but that won't matter in this case), and it'll be kinda slow if you're using it a lot, but it'll get the job done:

property _emailPatt : "[A-Z0-9._%-]+@[A-Z0-9._%-]+\\.[A-Z]{2,4}" -- junky pattern

set str to "email@hidden"

set isMatch to (do shell script ("python -c 'import sys, re; s = sys.argv[2].encode(\"utf8\"); match = re.compile(sys.argv[1].encode(\"utf8\"), re.U + re.I + re.S).match(s); print bool(match and match.end() == len(s))' " as Unicode text) & quoted form of _emailPatt & space & quoted form of str) is "True"

Or find yourself an ObjC re library and call into that via Studio's "call method" command. Or work out a suitable re pattern, then convert it into vanilla AS code (tedious, but doable).

HTH

has
--
http://freespace.virgin.net/hamish.sanderson/
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2011 Apple Inc. All rights reserved.