LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!
on mouseUp
put wordoffset ("http://", field "url") into http
put wordoffset ("www.", field "url") into httpwww
if http <> 1 then put "http://"&field "url" into field "url"
else
if httpwww <> 1 then put "http://www."&field "url" into field "url"
put url field "url" into field "main"
end if
end mouseUp
I know there is a better way to do this...
Can someone point me in the right direction?
Thanks!
Last edited by TodayIsTheDay on Fri Sep 11, 2009 4:08 pm, edited 1 time in total.
on mouseUp
if not (field "fURL" begins with "http") then put "http://" & field "fURL" into field "fURL"
end mouseUp
note that I replaced the name of the field "url" with "fURL". It is probably wise to stay away from reserved words for naming things in Rev.
regards
Bernd
But my code needs to check to see if the string starts with www. if not add that, then it needs to see if it starts with http:// if not add http://www.
I'm just not getting the logic order or something I'm needing to do this wit...
Maybe an easier way to explain it is I have a search box I can enter a url into.
If the string doesn't start with http://www. then it won't work...
if not field "url" begins with "www." then
put "www." & field "url" into field "url"
end if
if not field "url" begins with "http://" then
put "http://" & field "url" into field "url"
end if
Various teststacks and stuff:
http://bjoernke.com
Chat with other RunRev developers:
chat.freenode.net:6666 #livecode
on mouseUp
if not (field "furl" begins with "www.") then
put "www." & field "furl" into field "furl"
end if
if not (field "furl" begins with "http://") then
put "http://" & field "furl" into field "furl"
end if
end mouseUp
if you want to catch http without www then you can try this
on mouseUp
-- test for double negative
-- neither "http" nor "www" is in the beginning of the field
if not (field "furl" begins with "http") and not (field "furl" begins with "www") then
put "http://www." & field "furl" into field "furl"
else
-- test if field "furl" begins with "www"
if (field "furl" begins with "www") then put "http://" & field "furl" into field "furl"
-- test for completeness
-- if address starts with "http://" but has no "www" in it (can probably omitted)
if (field "furl" begins with "http://") and not (field "furl" contains "www.") then put "www." after char 7 of field "furl"
end if
end mouseUp
note that the field name I use is different from yours
regards
Bernd
could you give an example? To me it seems difficult to decide where to insert the @. If you only want to test whether the @ is in the address at all and then reject that mail-address that would be easy.
regards
Bernd
Something like this for email validation should help. Its not really possible to correct an addy on the fly of course, just possible to check if it resembles the correct format.
on mouseUp
if not (field "furl" begins with "@") and (field "furl" contains "@") then
-- This would indicate theres a good chance the email addy is valid.
--It doesn't START with @ but does contain one.
put "Email is valid format"
else
-- Fails the test, most likely is an invalid email, warn the user.
put "Email format is invalid"
end if
end mouseUp
user#606 wrote:I found that most useful, but any ideas to correct e-mail addresses?
the missing@ for example.
in my case, the WWW. bit works fine, even though the data is beyond correction by the user. The file is being saved by then, for instance.