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!
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
-
TodayIsTheDay
- Posts: 56
- Joined: Sat Jun 20, 2009 2:41 pm
Post
by TodayIsTheDay » Fri Sep 11, 2009 3:37 pm
I have a text box and button...I'm trying to see if the beginning of a string in the text box starts with www. or http://, if not add them...
I came up with this:
Code: Select all
if field "url" begins with "www." then put "http://"&field "url" into field "url"
It works but would it be better to say if field does not start with? I have searched for does not, etc but haven't found a way to do it...
I've also tried this:
Code: Select all
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.
-
BvG
- VIP Livecode Opensource Backer

- Posts: 1239
- Joined: Sat Apr 08, 2006 1:10 pm
-
Contact:
Post
by BvG » Fri Sep 11, 2009 4:05 pm
I agree that the negative to "begins with" is missing. as a workaround, you can use "not" in the strangest places.
Code: Select all
if not field "url" begins with "http://" then put "http://" before field "url"
Various teststacks and stuff:
http://bjoernke.com
Chat with other RunRev developers:
chat.freenode.net:6666 #livecode
-
bn
- VIP Livecode Opensource Backer

- Posts: 4172
- Joined: Sun Jan 07, 2007 9:12 pm
Post
by bn » Fri Sep 11, 2009 4:17 pm
for me it only works with brackets:
Code: Select all
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
-
TodayIsTheDay
- Posts: 56
- Joined: Sat Jun 20, 2009 2:41 pm
Post
by TodayIsTheDay » Fri Sep 11, 2009 4:23 pm
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...
-
BvG
- VIP Livecode Opensource Backer

- Posts: 1239
- Joined: Sat Apr 08, 2006 1:10 pm
-
Contact:
Post
by BvG » Fri Sep 11, 2009 4:38 pm
more like this?
Code: Select all
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
-
TodayIsTheDay
- Posts: 56
- Joined: Sat Jun 20, 2009 2:41 pm
Post
by TodayIsTheDay » Fri Sep 11, 2009 5:03 pm
hmmm. something like that but I can't get that to work... Am I doing something wrong?
-
TodayIsTheDay
- Posts: 56
- Joined: Sat Jun 20, 2009 2:41 pm
Post
by TodayIsTheDay » Fri Sep 11, 2009 5:19 pm
I've also tried this:
Code: Select all
if not field "url" begins with "http://www." then put "http://www." & field "url" into field "url"
put url field "url" into field "main"
That doesn't work at all.
It also doesn't take into account if you've typed
www.domain.com or
http://domain.com into the box
-
bn
- VIP Livecode Opensource Backer

- Posts: 4172
- Joined: Sun Jan 07, 2007 9:12 pm
Post
by bn » Fri Sep 11, 2009 5:24 pm
if you put in the brackets Björnkes code works
Code: Select all
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
Code: Select all
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
-
TodayIsTheDay
- Posts: 56
- Joined: Sat Jun 20, 2009 2:41 pm
Post
by TodayIsTheDay » Fri Sep 11, 2009 6:04 pm
Thank you guys. The last code sample does exactly what I was looking for. It also taught me a couple of new things...
I'm sure I'll have more questions later...
Thanks again!

-
user#606
- Posts: 217
- Joined: Sun Jan 27, 2008 12:25 pm
-
Contact:
Post
by user#606 » Fri Sep 11, 2009 6:29 pm
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.
-
bn
- VIP Livecode Opensource Backer

- Posts: 4172
- Joined: Sun Jan 07, 2007 9:12 pm
Post
by bn » Fri Sep 11, 2009 6:34 pm
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
-
sturgis
- Livecode Opensource Backer

- Posts: 1685
- Joined: Sat Feb 28, 2009 11:49 pm
Post
by sturgis » Fri Oct 02, 2009 2:52 am
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.
And hi again everyone, I may be back momentarily.
Code: Select all
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.
-
bn
- VIP Livecode Opensource Backer

- Posts: 4172
- Joined: Sun Jan 07, 2007 9:12 pm
Post
by bn » Fri Oct 02, 2009 9:48 am
Hi Sturgis,
good to see you back.
I hope it is going to be a long moment...
regards
Bernd